iwer 2.2.0 → 2.2.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.
@@ -1369,6 +1369,7 @@ const P_SPACE = Symbol('@iwer/xr-space');
1369
1369
  const P_VIEW = Symbol('@iwer/xr-view');
1370
1370
  const P_VIEWPORT = Symbol('@iwer/xr-viewport');
1371
1371
  const P_RAY = Symbol('@iwer/xr-ray');
1372
+ const P_DEPTH_INFO = Symbol('@iwer/xr-depth-info');
1372
1373
  const P_HIT_TEST = Symbol('@iwer/xr-hit-test');
1373
1374
 
1374
1375
  /**
@@ -1877,6 +1878,34 @@ function slerpQuat(a, b, t) {
1877
1878
  w: s0 * a.w + s1 * bw,
1878
1879
  };
1879
1880
  }
1881
+ /**
1882
+ * Map of common device name aliases to canonical DeviceId values.
1883
+ * Enables callers to use natural variants like "right", "left-controller",
1884
+ * "controllers.right", etc. in addition to the canonical names.
1885
+ */
1886
+ const DEVICE_ID_ALIASES = {
1887
+ right: 'controller-right',
1888
+ left: 'controller-left',
1889
+ 'right-controller': 'controller-right',
1890
+ 'left-controller': 'controller-left',
1891
+ 'controllers.right': 'controller-right',
1892
+ 'controllers.left': 'controller-left',
1893
+ rightController: 'controller-right',
1894
+ leftController: 'controller-left',
1895
+ 'right-hand': 'hand-right',
1896
+ 'left-hand': 'hand-left',
1897
+ 'hands.right': 'hand-right',
1898
+ 'hands.left': 'hand-left',
1899
+ rightHand: 'hand-right',
1900
+ leftHand: 'hand-left',
1901
+ };
1902
+ /**
1903
+ * Resolve a device identifier, accepting both canonical names and common aliases.
1904
+ */
1905
+ function resolveDeviceId(id) {
1906
+ var _a;
1907
+ return (_a = DEVICE_ID_ALIASES[id]) !== null && _a !== void 0 ? _a : id;
1908
+ }
1880
1909
  /**
1881
1910
  * RemoteControlInterface provides frame-synchronized programmatic control of an XRDevice.
1882
1911
  *
@@ -2011,15 +2040,27 @@ class RemoteControlInterface {
2011
2040
  action.elapsedMs += deltaTimeMs;
2012
2041
  if (action.elapsedMs >= action.durationMs) {
2013
2042
  // Complete - apply final state
2014
- this.applyDurationFinalState(action);
2015
- action.resolve(this.getDurationResult(action));
2043
+ try {
2044
+ this.applyDurationFinalState(action);
2045
+ action.resolve(this.getDurationResult(action));
2046
+ }
2047
+ catch (error) {
2048
+ action.reject(error);
2049
+ }
2016
2050
  this.commandQueue.shift();
2017
2051
  // Continue to next action
2018
2052
  }
2019
2053
  else {
2020
2054
  // In progress - lerp
2021
- const t = action.elapsedMs / action.durationMs;
2022
- this.applyDurationLerpState(action, t);
2055
+ try {
2056
+ const t = action.elapsedMs / action.durationMs;
2057
+ this.applyDurationLerpState(action, t);
2058
+ }
2059
+ catch (error) {
2060
+ action.reject(error);
2061
+ this.commandQueue.shift();
2062
+ continue;
2063
+ }
2023
2064
  // Stop processing - wait for next frame
2024
2065
  break;
2025
2066
  }
@@ -2777,6 +2818,10 @@ class RemoteControlInterface {
2777
2818
  */
2778
2819
  async dispatch(method, params = {}) {
2779
2820
  var _a;
2821
+ // Normalize device identifier aliases (e.g. "right" -> "controller-right")
2822
+ if (typeof params.device === 'string') {
2823
+ params.device = resolveDeviceId(params.device);
2824
+ }
2780
2825
  // Immediate methods execute synchronously without queue
2781
2826
  if (RemoteControlInterface.IMMEDIATE_METHODS.has(method)) {
2782
2827
  // Active immediate methods trigger capture mode
@@ -2856,6 +2901,8 @@ class RemoteControlInterface {
2856
2901
  */
2857
2902
  executeSelectSequence(params) {
2858
2903
  const { device: deviceId, duration = 0.15 } = params;
2904
+ // Validate device upfront to prevent sub-actions from failing in the frame loop
2905
+ this.getDeviceSelectValue(deviceId);
2859
2906
  return new Promise((resolve, reject) => {
2860
2907
  // Track completion of all three actions
2861
2908
  let actionsCompleted = 0;
@@ -3574,6 +3621,60 @@ class NativePlane {
3574
3621
  }
3575
3622
  }
3576
3623
 
3624
+ /**
3625
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3626
+ *
3627
+ * This source code is licensed under the MIT license found in the
3628
+ * LICENSE file in the root directory of this source tree.
3629
+ */
3630
+ class XRCPUDepthInformation {
3631
+ constructor(data, width, height, normDepthBufferFromNormView, rawValueToMeters, dataFormat) {
3632
+ this[P_DEPTH_INFO] = {
3633
+ data,
3634
+ width,
3635
+ height,
3636
+ normDepthBufferFromNormView,
3637
+ rawValueToMeters,
3638
+ dataFormat,
3639
+ };
3640
+ }
3641
+ get data() {
3642
+ return this[P_DEPTH_INFO].data;
3643
+ }
3644
+ get width() {
3645
+ return this[P_DEPTH_INFO].width;
3646
+ }
3647
+ get height() {
3648
+ return this[P_DEPTH_INFO].height;
3649
+ }
3650
+ get normDepthBufferFromNormView() {
3651
+ return this[P_DEPTH_INFO].normDepthBufferFromNormView;
3652
+ }
3653
+ get rawValueToMeters() {
3654
+ return this[P_DEPTH_INFO].rawValueToMeters;
3655
+ }
3656
+ getDepthInMeters(x, y) {
3657
+ const { width, height, rawValueToMeters, data, dataFormat } = this[P_DEPTH_INFO];
3658
+ if (x < 0 || x >= 1 || y < 0 || y >= 1) {
3659
+ throw new RangeError('Normalized coordinates must be in [0, 1) range.');
3660
+ }
3661
+ const col = Math.floor(x * width);
3662
+ const row = Math.floor(y * height);
3663
+ if (dataFormat === 'float32') {
3664
+ const floatView = new Float32Array(data);
3665
+ const index = row * width + col;
3666
+ return floatView[index] * rawValueToMeters;
3667
+ }
3668
+ else {
3669
+ // luminance-alpha: 16-bit unsigned int packed as two bytes
3670
+ const byteView = new Uint8Array(data);
3671
+ const index = (row * width + col) * 2;
3672
+ const rawValue = byteView[index] + byteView[index + 1] * 256;
3673
+ return rawValue * rawValueToMeters;
3674
+ }
3675
+ }
3676
+ }
3677
+
3577
3678
  /**
3578
3679
  * Copyright (c) Meta Platforms, Inc. and affiliates.
3579
3680
  *
@@ -4075,6 +4176,7 @@ class XRFrame {
4075
4176
  detectedMeshes: new XRMeshSet(),
4076
4177
  trackedAnchors: session[P_SESSION].frameTrackedAnchors,
4077
4178
  hitTestResultsMap: new Map(),
4179
+ depthDataMap: new Map(),
4078
4180
  };
4079
4181
  }
4080
4182
  get session() {
@@ -4210,6 +4312,16 @@ class XRFrame {
4210
4312
  return [...this[P_FRAME].hitTestResultsMap.get(hitTestSource)];
4211
4313
  }
4212
4314
  }
4315
+ getDepthInformation(view) {
4316
+ var _a;
4317
+ if (!this[P_FRAME].active) {
4318
+ throw new DOMException('XRFrame access outside the callback that produced it is invalid.', 'InvalidStateError');
4319
+ }
4320
+ if (!this[P_FRAME].session[P_SESSION].enabledFeatures.includes('depth-sensing')) {
4321
+ throw new DOMException('depth-sensing feature is not enabled on this session.', 'InvalidStateError');
4322
+ }
4323
+ return (_a = this[P_FRAME].depthDataMap.get(view[P_VIEW].eye)) !== null && _a !== void 0 ? _a : null;
4324
+ }
4213
4325
  }
4214
4326
 
4215
4327
  /**
@@ -4357,6 +4469,9 @@ class XRSession extends EventTarget {
4357
4469
  if (this[P_SESSION].enabledFeatures.includes('mesh-detection')) {
4358
4470
  this[P_SESSION].updateTrackedMeshes(frame);
4359
4471
  }
4472
+ if (this[P_SESSION].enabledFeatures.includes('depth-sensing')) {
4473
+ this[P_SESSION].computeDepthSensing(frame);
4474
+ }
4360
4475
  if (this[P_SESSION].enabledFeatures.includes('hit-test')) {
4361
4476
  this[P_SESSION].computeHitTestResults(frame);
4362
4477
  }
@@ -4482,6 +4597,37 @@ class XRSession extends EventTarget {
4482
4597
  frame[P_FRAME].detectedMeshes.add(xrMesh);
4483
4598
  });
4484
4599
  },
4600
+ depthSensingUsage: 'cpu-optimized',
4601
+ depthSensingDataFormat: 'float32',
4602
+ computeDepthSensing: (frame) => {
4603
+ const sem = this[P_SESSION].device[P_DEVICE].sem;
4604
+ if (!sem)
4605
+ return;
4606
+ const { depthNear, depthFar } = this[P_SESSION].renderState;
4607
+ const baseLayer = this[P_SESSION].renderState.baseLayer;
4608
+ if (!baseLayer)
4609
+ return;
4610
+ const canvas = baseLayer.context.canvas;
4611
+ // Use a reduced resolution for depth buffer (1/4 of canvas)
4612
+ const depthWidth = Math.max(1, Math.floor(canvas.width / 4));
4613
+ const depthHeight = Math.max(1, Math.floor(canvas.height / 4));
4614
+ const eyes = this[P_SESSION].mode === 'inline'
4615
+ ? [XREye.None]
4616
+ : [XREye.Left, XREye.Right];
4617
+ for (const eye of eyes) {
4618
+ const projectionMatrix = this[P_SESSION].getProjectionMatrix(eye);
4619
+ const viewSpace = this[P_SESSION].device.viewSpaces[eye];
4620
+ const viewGlobalMatrix = XRSpaceUtils.calculateGlobalOffsetMatrix(viewSpace);
4621
+ const viewMatrix = create$5();
4622
+ invert(viewMatrix, viewGlobalMatrix);
4623
+ const result = sem.computeDepthBuffer(viewMatrix, projectionMatrix, depthWidth, depthHeight, depthNear, depthFar);
4624
+ if (result) {
4625
+ const depthInfo = new XRCPUDepthInformation(result.data, result.width, result.height, new XRRigidTransform(), // identity: depth buffer is aligned with view
4626
+ result.rawValueToMeters, this[P_SESSION].depthSensingDataFormat);
4627
+ frame[P_FRAME].depthDataMap.set(eye, depthInfo);
4628
+ }
4629
+ }
4630
+ },
4485
4631
  hitTestSources: new Set(),
4486
4632
  computeHitTestResults: (frame) => {
4487
4633
  const sem = this[P_SESSION].device[P_DEVICE].sem;
@@ -4551,6 +4697,12 @@ class XRSession extends EventTarget {
4551
4697
  get interactionMode() {
4552
4698
  return this[P_SESSION].device[P_DEVICE].interactionMode;
4553
4699
  }
4700
+ get depthUsage() {
4701
+ return this[P_SESSION].depthSensingUsage;
4702
+ }
4703
+ get depthDataFormat() {
4704
+ return this[P_SESSION].depthSensingDataFormat;
4705
+ }
4554
4706
  updateRenderState(state = {}) {
4555
4707
  var _a, _b, _c, _d;
4556
4708
  if (this[P_SESSION].ended) {
@@ -6033,7 +6185,7 @@ class ActionPlayer {
6033
6185
  }
6034
6186
  }
6035
6187
 
6036
- const VERSION = "2.2.0";
6188
+ const VERSION = "2.2.1";
6037
6189
 
6038
6190
  /**
6039
6191
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -10121,4 +10273,4 @@ class ActionRecorder {
10121
10273
  }
10122
10274
  }
10123
10275
 
10124
- export { ActionRecorder, NativeMesh, NativePlane, P_ACTION_PLAYER, P_ACTION_RECORDER, P_ANCHOR, P_CONTROLLER, P_DEVICE, P_FRAME, P_GAMEPAD, P_HAND_INPUT, P_HIT_TEST, P_INPUT_SOURCE, P_JOINT_POSE, P_JOINT_SPACE, P_MESH, P_PLANE, P_POSE, P_RAY, P_REF_SPACE, P_RENDER_STATE, P_RIGID_TRANSFORM, P_SESSION, P_SPACE, P_SYSTEM, P_TRACKED_INPUT, P_VIEW, P_VIEWER_POSE, P_VIEWPORT, P_WEBGL_LAYER, RemoteControlInterface, XRAnchor, XRAnchorSet, XRDevice, XRFrame, XRHand, XRInputSource, XRInputSourceArray, XRInputSourceEvent, XRInputSourcesChangeEvent, XRJointPose, XRJointSpace, XRLayer, XRMesh, XRMeshSet, XRPlane, XRPlaneSet, XRPose, XRRay, XRReferenceSpace, XRReferenceSpaceEvent, XRRenderState, XRRigidTransform, XRSemanticLabels, XRSession, XRSessionEvent, XRSpace, XRSystem, XRView, XRViewerPose, XRViewport, XRWebGLLayer, directionTo, eulerToQuat, lookRotation, metaQuest2, metaQuest3, metaQuestPro, oculusQuest1, quatToEuler, quatToObj, vec3ToObj, waitForCondition };
10276
+ export { ActionRecorder, NativeMesh, NativePlane, P_ACTION_PLAYER, P_ACTION_RECORDER, P_ANCHOR, P_CONTROLLER, P_DEPTH_INFO, P_DEVICE, P_FRAME, P_GAMEPAD, P_HAND_INPUT, P_HIT_TEST, P_INPUT_SOURCE, P_JOINT_POSE, P_JOINT_SPACE, P_MESH, P_PLANE, P_POSE, P_RAY, P_REF_SPACE, P_RENDER_STATE, P_RIGID_TRANSFORM, P_SESSION, P_SPACE, P_SYSTEM, P_TRACKED_INPUT, P_VIEW, P_VIEWER_POSE, P_VIEWPORT, P_WEBGL_LAYER, RemoteControlInterface, XRAnchor, XRAnchorSet, XRCPUDepthInformation, XRDevice, XRFrame, XRHand, XRInputSource, XRInputSourceArray, XRInputSourceEvent, XRInputSourcesChangeEvent, XRJointPose, XRJointSpace, XRLayer, XRMesh, XRMeshSet, XRPlane, XRPlaneSet, XRPose, XRRay, XRReferenceSpace, XRReferenceSpaceEvent, XRRenderState, XRRigidTransform, XRSemanticLabels, XRSession, XRSessionEvent, XRSpace, XRSystem, XRView, XRViewerPose, XRViewport, XRWebGLLayer, directionTo, eulerToQuat, lookRotation, metaQuest2, metaQuest3, metaQuestPro, oculusQuest1, quatToEuler, quatToObj, vec3ToObj, waitForCondition };