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.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,6 +2918,17 @@ 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
|
+
}
|
|
2926
|
+
if (this[P_SESSION].mode === 'immersive-ar') {
|
|
2927
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
2928
|
+
if (sem) {
|
|
2929
|
+
sem.render(time);
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2917
2932
|
if (this[P_SESSION].enabledFeatures.includes('anchors')) {
|
|
2918
2933
|
this[P_SESSION].updateTrackedAnchors();
|
|
2919
2934
|
}
|
|
@@ -3002,15 +3017,21 @@ class XRSession extends EventTarget {
|
|
|
3002
3017
|
},
|
|
3003
3018
|
trackedPlanes: new Map(),
|
|
3004
3019
|
updateTrackedPlanes: (frame) => {
|
|
3005
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3020
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3006
3021
|
if (!sem) {
|
|
3007
3022
|
return;
|
|
3008
3023
|
}
|
|
3024
|
+
const trackedPlanes = Array.from(this[P_SESSION].trackedPlanes.keys());
|
|
3025
|
+
trackedPlanes.forEach((plane) => {
|
|
3026
|
+
if (!sem.trackedPlanes.has(plane)) {
|
|
3027
|
+
this[P_SESSION].trackedPlanes.delete(plane);
|
|
3028
|
+
}
|
|
3029
|
+
});
|
|
3009
3030
|
sem.trackedPlanes.forEach((plane) => {
|
|
3010
3031
|
let xrPlane = this[P_SESSION].trackedPlanes.get(plane);
|
|
3011
3032
|
if (!xrPlane) {
|
|
3012
3033
|
const planeSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, plane.transform.matrix);
|
|
3013
|
-
xrPlane = new XRPlane(plane, planeSpace, plane.polygon);
|
|
3034
|
+
xrPlane = new XRPlane(plane, planeSpace, plane.polygon, plane.semanticLabel);
|
|
3014
3035
|
this[P_SESSION].trackedPlanes.set(plane, xrPlane);
|
|
3015
3036
|
}
|
|
3016
3037
|
xrPlane[P_PLANE].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3020,15 +3041,21 @@ class XRSession extends EventTarget {
|
|
|
3020
3041
|
},
|
|
3021
3042
|
trackedMeshes: new Map(),
|
|
3022
3043
|
updateTrackedMeshes: (frame) => {
|
|
3023
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3044
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3024
3045
|
if (!sem) {
|
|
3025
3046
|
return;
|
|
3026
3047
|
}
|
|
3048
|
+
const trackedMeshes = Array.from(this[P_SESSION].trackedMeshes.keys());
|
|
3049
|
+
trackedMeshes.forEach((mesh) => {
|
|
3050
|
+
if (!sem.trackedMeshes.has(mesh)) {
|
|
3051
|
+
this[P_SESSION].trackedMeshes.delete(mesh);
|
|
3052
|
+
}
|
|
3053
|
+
});
|
|
3027
3054
|
sem.trackedMeshes.forEach((mesh) => {
|
|
3028
3055
|
let xrMesh = this[P_SESSION].trackedMeshes.get(mesh);
|
|
3029
3056
|
if (!xrMesh) {
|
|
3030
3057
|
const meshSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, mesh.transform.matrix);
|
|
3031
|
-
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices);
|
|
3058
|
+
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices, mesh.semanticLabel);
|
|
3032
3059
|
this[P_SESSION].trackedMeshes.set(mesh, xrMesh);
|
|
3033
3060
|
}
|
|
3034
3061
|
xrMesh[P_MESH].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3038,7 +3065,7 @@ class XRSession extends EventTarget {
|
|
|
3038
3065
|
},
|
|
3039
3066
|
hitTestSources: new Set(),
|
|
3040
3067
|
computeHitTestResults: (frame) => {
|
|
3041
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3068
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3042
3069
|
if (!sem)
|
|
3043
3070
|
return;
|
|
3044
3071
|
const globalSpace = this[P_SESSION].device[P_DEVICE].globalSpace;
|
|
@@ -3272,7 +3299,7 @@ class XRSession extends EventTarget {
|
|
|
3272
3299
|
else if (this[P_SESSION].ended) {
|
|
3273
3300
|
reject(new DOMException('XRSession has already ended.', 'InvalidStateError'));
|
|
3274
3301
|
}
|
|
3275
|
-
else if (!this[P_SESSION].device[P_DEVICE].
|
|
3302
|
+
else if (!this[P_SESSION].device[P_DEVICE].sem) {
|
|
3276
3303
|
reject(new DOMException('Synthethic Environment Module required for emulating hit-test', 'OperationError'));
|
|
3277
3304
|
}
|
|
3278
3305
|
else {
|
|
@@ -4587,7 +4614,7 @@ class ActionPlayer {
|
|
|
4587
4614
|
}
|
|
4588
4615
|
}
|
|
4589
4616
|
|
|
4590
|
-
const VERSION = "
|
|
4617
|
+
const VERSION = "2.0.0";
|
|
4591
4618
|
|
|
4592
4619
|
/**
|
|
4593
4620
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -4615,28 +4642,9 @@ class XRReferenceSpaceEvent extends Event {
|
|
|
4615
4642
|
class XRSystem extends EventTarget {
|
|
4616
4643
|
constructor(device) {
|
|
4617
4644
|
super();
|
|
4618
|
-
this[P_SYSTEM] = {
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
isSessionSupported(mode) {
|
|
4622
|
-
return new Promise((resolve, _reject) => {
|
|
4623
|
-
if (mode === 'inline') {
|
|
4624
|
-
resolve(true);
|
|
4625
|
-
}
|
|
4626
|
-
else {
|
|
4627
|
-
// Check for spatial tracking permission if necessary
|
|
4628
|
-
resolve(this[P_SYSTEM].device.supportedSessionModes.includes(mode));
|
|
4629
|
-
}
|
|
4630
|
-
});
|
|
4631
|
-
}
|
|
4632
|
-
requestSession(mode, options = {}) {
|
|
4633
|
-
return new Promise((resolve, reject) => {
|
|
4634
|
-
this.isSessionSupported(mode)
|
|
4635
|
-
.then((isSupported) => {
|
|
4636
|
-
if (!isSupported) {
|
|
4637
|
-
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4638
|
-
return;
|
|
4639
|
-
}
|
|
4645
|
+
this[P_SYSTEM] = {
|
|
4646
|
+
device,
|
|
4647
|
+
grantSession: ({ resolve, reject, mode, options }) => {
|
|
4640
4648
|
// Check for active sessions and other constraints here
|
|
4641
4649
|
if (this[P_SYSTEM].activeSession) {
|
|
4642
4650
|
reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
|
|
@@ -4668,6 +4676,54 @@ class XRSystem extends EventTarget {
|
|
|
4668
4676
|
this[P_SYSTEM].activeSession = undefined;
|
|
4669
4677
|
});
|
|
4670
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
|
+
};
|
|
4671
4727
|
})
|
|
4672
4728
|
.catch(reject);
|
|
4673
4729
|
});
|
|
@@ -4711,6 +4767,10 @@ const DEFAULTS = {
|
|
|
4711
4767
|
headsetQuaternion: new Quaternion(),
|
|
4712
4768
|
stereoEnabled: false,
|
|
4713
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;
|
|
4714
4774
|
/**
|
|
4715
4775
|
* XRDevice is not a standard API class outlined in the WebXR Device API Specifications
|
|
4716
4776
|
* Instead, it serves as an user-facing interface to control the emulated XR Device
|
|
@@ -4718,6 +4778,7 @@ const DEFAULTS = {
|
|
|
4718
4778
|
class XRDevice {
|
|
4719
4779
|
constructor(deviceConfig, deviceOptions = {}) {
|
|
4720
4780
|
var _a, _b, _c, _d, _e, _f;
|
|
4781
|
+
this.version = VERSION;
|
|
4721
4782
|
const globalSpace = new GlobalSpace();
|
|
4722
4783
|
const viewerSpace = new XRReferenceSpace(XRReferenceSpaceType.Viewer, globalSpace);
|
|
4723
4784
|
const viewSpaces = {
|
|
@@ -4803,12 +4864,27 @@ class XRDevice {
|
|
|
4803
4864
|
// backup canvas data
|
|
4804
4865
|
const canvas = baseLayer.context.canvas;
|
|
4805
4866
|
if (canvas.parentElement !== this[P_DEVICE].canvasContainer) {
|
|
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;
|
|
4876
|
+
if (sem) {
|
|
4877
|
+
sem.environmentCanvas.style.zIndex = Z_INDEX_SEM_CANVAS.toString();
|
|
4878
|
+
this[P_DEVICE].canvasContainer.appendChild(sem.environmentCanvas);
|
|
4879
|
+
}
|
|
4806
4880
|
this[P_DEVICE].canvasData = {
|
|
4807
4881
|
canvas,
|
|
4808
4882
|
parent: canvas.parentElement,
|
|
4809
4883
|
width: canvas.width,
|
|
4810
4884
|
height: canvas.height,
|
|
4885
|
+
zIndex: canvas.style.zIndex,
|
|
4811
4886
|
};
|
|
4887
|
+
canvas.style.zIndex = Z_INDEX_APP_CANVAS.toString();
|
|
4812
4888
|
this[P_DEVICE].canvasContainer.appendChild(canvas);
|
|
4813
4889
|
document.body.appendChild(this[P_DEVICE].canvasContainer);
|
|
4814
4890
|
}
|
|
@@ -4817,16 +4893,27 @@ class XRDevice {
|
|
|
4817
4893
|
},
|
|
4818
4894
|
onSessionEnd: () => {
|
|
4819
4895
|
if (this[P_DEVICE].canvasData) {
|
|
4820
|
-
const { canvas, parent, width, height } = this[P_DEVICE].canvasData;
|
|
4896
|
+
const { canvas, parent, width, height, zIndex } = this[P_DEVICE].canvasData;
|
|
4821
4897
|
canvas.width = width;
|
|
4822
4898
|
canvas.height = height;
|
|
4899
|
+
canvas.style.zIndex = zIndex;
|
|
4823
4900
|
if (parent) {
|
|
4824
4901
|
parent.appendChild(canvas);
|
|
4825
4902
|
}
|
|
4826
4903
|
else {
|
|
4827
4904
|
this[P_DEVICE].canvasContainer.removeChild(canvas);
|
|
4828
4905
|
}
|
|
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;
|
|
4912
|
+
if (sem) {
|
|
4913
|
+
this[P_DEVICE].canvasContainer.removeChild(sem.environmentCanvas);
|
|
4914
|
+
}
|
|
4829
4915
|
document.body.removeChild(this[P_DEVICE].canvasContainer);
|
|
4916
|
+
this[P_DEVICE].canvasData = undefined;
|
|
4830
4917
|
window.dispatchEvent(new Event('resize'));
|
|
4831
4918
|
}
|
|
4832
4919
|
},
|
|
@@ -4911,8 +4998,11 @@ class XRDevice {
|
|
|
4911
4998
|
globalObject['XRInputSourcesChangeEvent'] = XRInputSourcesChangeEvent;
|
|
4912
4999
|
globalObject['XRReferenceSpaceEvent'] = XRReferenceSpaceEvent;
|
|
4913
5000
|
}
|
|
4914
|
-
|
|
4915
|
-
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);
|
|
4916
5006
|
}
|
|
4917
5007
|
get supportedSessionModes() {
|
|
4918
5008
|
return this[P_DEVICE].supportedSessionModes;
|
|
@@ -5008,10 +5098,32 @@ class XRDevice {
|
|
|
5008
5098
|
get canvasContainer() {
|
|
5009
5099
|
return this[P_DEVICE].canvasContainer;
|
|
5010
5100
|
}
|
|
5101
|
+
get canvasDimensions() {
|
|
5102
|
+
if (this[P_DEVICE].canvasData) {
|
|
5103
|
+
const { width, height } = this[P_DEVICE].canvasData.canvas;
|
|
5104
|
+
return { width, height };
|
|
5105
|
+
}
|
|
5106
|
+
return;
|
|
5107
|
+
}
|
|
5011
5108
|
get activeSession() {
|
|
5012
5109
|
var _a;
|
|
5013
5110
|
return (_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM].activeSession;
|
|
5014
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
|
+
}
|
|
5015
5127
|
recenter() {
|
|
5016
5128
|
const deltaVec = new Vector3(-this.position.x, 0, -this.position.z);
|
|
5017
5129
|
const forward = new Vector3(0, 0, -1).applyQuaternion(this.quaternion);
|
|
@@ -5047,6 +5159,12 @@ class XRDevice {
|
|
|
5047
5159
|
this[P_DEVICE].actionPlayer = new ActionPlayer(refSpace, recording, this[P_DEVICE].ipd);
|
|
5048
5160
|
return this[P_DEVICE].actionPlayer;
|
|
5049
5161
|
}
|
|
5162
|
+
get devui() {
|
|
5163
|
+
return this[P_DEVICE].devui;
|
|
5164
|
+
}
|
|
5165
|
+
get sem() {
|
|
5166
|
+
return this[P_DEVICE].sem;
|
|
5167
|
+
}
|
|
5050
5168
|
}
|
|
5051
5169
|
|
|
5052
5170
|
/**
|