Skip to content

Commit 4a685d0

Browse files
authored
Merge pull request #359 from De-Panther/webxr_tracked_display
Renamed WebXR HMD to WebXR Tracked Display and fixed its mapping
2 parents ba7feab + ac291d5 commit 4a685d0

File tree

7 files changed

+55
-25
lines changed

7 files changed

+55
-25
lines changed

Packages/webxr-interactions/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
### Fixed
1818
- SceneHitTest now updates the pose of the originTransform instead of WebXRManager transform.
19+
- Mapping of WebXR Tracked Display device.
1920

2021
## [0.20.0] - 2023-12-18
2122
### Added

Packages/webxr-interactions/Runtime/InputSystem/WebXRInputDevices.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@
1111
namespace WebXR.InputSystem
1212
{
1313
using InputSystem = UnityEngine.InputSystem.InputSystem;
14+
15+
#if UNITY_EDITOR
16+
[UnityEditor.InitializeOnLoad]
17+
#endif
18+
[Preserve, InputControlLayout(displayName = "WebXR Tracked Display")]
19+
internal class WebXRTrackedDisplay : XRHMD
20+
{
21+
static WebXRTrackedDisplay()
22+
{
23+
InputSystem.RegisterLayout<WebXRTrackedDisplay>(
24+
matches: new InputDeviceMatcher()
25+
.WithInterface(XRUtilities.InterfaceMatchAnyVersion)
26+
.WithProduct("WebXR Tracked Display"));
27+
}
28+
29+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
30+
private static void InitializeInPlayer() { }
31+
}
32+
1433
[Preserve]
1534
public struct WebXRControllerState : IInputStateTypeInfo
1635
{
@@ -158,7 +177,10 @@ public class WebXRController : XRControllerWithRumble
158177

159178
static WebXRController()
160179
{
161-
InputSystem.RegisterLayout<WebXRController>();
180+
InputSystem.RegisterLayout<WebXRController>(
181+
matches: new InputDeviceMatcher()
182+
.WithInterface(XRUtilities.InterfaceMatchAnyVersion)
183+
.WithProduct("WebXR Controller"));
162184
}
163185

164186
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine.InputSystem;
55
using UnityEngine.InputSystem.Layouts;
66
using UnityEngine.InputSystem.LowLevel;
7+
78
#if XR_HANDS_1_1_OR_NEWER
89
using System.Collections;
910
using System.Collections.Generic;
@@ -69,9 +70,7 @@ private void Awake()
6970
return;
7071
}
7172
initialized = true;
72-
InputSystem.RegisterLayout<WebXRController>(
73-
matches: new InputDeviceMatcher()
74-
.WithInterface("WebXRController"));
73+
7574
#if XR_HANDS_1_1_OR_NEWER
7675
var descriptors = new List<XRHandSubsystemDescriptor>();
7776
SubsystemManager.GetSubsystemDescriptors(descriptors);
@@ -346,18 +345,12 @@ private static IEnumerator RemoveDeviceAfterFrame(UnityEngine.InputSystem.InputD
346345

347346
private static WebXRController GetWebXRController(int hand)
348347
{
349-
string product = "WebXRController Left";
350-
string usage = "LeftHand";
351-
if (hand == 2)
352-
{
353-
product = "WebXRController Right";
354-
usage = "RightHand";
355-
}
348+
string usage = hand == 2 ? "RightHand" : "LeftHand";
356349
var device = InputSystem.AddDevice(
357350
new InputDeviceDescription
358351
{
359-
interfaceName = "WebXRController",
360-
product = product
352+
interfaceName = "XRInput",
353+
product = "WebXR Controller"
361354
});
362355
InputSystem.AddDeviceUsage(device, usage);
363356
return (WebXRController)device;

Packages/webxr/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313
- XR Hand pinch is now detected manually instead of relying on system select event, to support Apple Vision Pro.
14+
- Renamed WebXR HMD to WebXR Tracked Display.
1415

1516
### Fixed
1617
- Errors of Module._malloc and Module._free are not functions.
18+
- Mapping of WebXR Tracked Display device.
1719

1820
## [0.21.0] - 2024-01-17
1921
### Added

Packages/webxr/Runtime/Plugins/WebGL/WebXRTrackingProvider.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ UnitySubsystemErrorCode WebXRTrackingProvider::FillDeviceDefinition(UnityXRInter
5555
{
5656
// Fill in your connected device information here when requested. Used to create customized device states.
5757
auto &input = *m_Ctx.input;
58-
input.DeviceDefinition_SetName(definition, "WebXRHMD");
58+
input.DeviceDefinition_SetName(definition, "WebXR Tracked Display");
5959
input.DeviceDefinition_SetCharacteristics(definition, (UnityXRInputDeviceCharacteristics)(kUnityXRInputDeviceCharacteristicsHeadMounted | kUnityXRInputDeviceCharacteristicsTrackedDevice));
6060
input.DeviceDefinition_SetManufacturer(definition, "WebXR");
6161

62-
input.DeviceDefinition_AddFeatureWithUsage(definition, "head position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageCenterEyePosition);
63-
input.DeviceDefinition_AddFeatureWithUsage(definition, "head rotation", kUnityXRInputFeatureTypeRotation, kUnityXRInputFeatureUsageCenterEyeRotation);
62+
input.DeviceDefinition_AddFeatureWithUsage(definition, "is tracked", kUnityXRInputFeatureTypeBinary, kUnityXRInputFeatureUsageIsTracked);
63+
input.DeviceDefinition_AddFeatureWithUsage(definition, "tracking state", kUnityXRInputFeatureTypeDiscreteStates, kUnityXRInputFeatureUsageTrackingState);
64+
65+
input.DeviceDefinition_AddFeatureWithUsage(definition, "device position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageDevicePosition);
66+
input.DeviceDefinition_AddFeatureWithUsage(definition, "device rotation", kUnityXRInputFeatureTypeRotation, kUnityXRInputFeatureUsageDeviceRotation);
67+
input.DeviceDefinition_AddFeatureWithUsage(definition, "center eye position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageCenterEyePosition);
68+
input.DeviceDefinition_AddFeatureWithUsage(definition, "center eye rotation", kUnityXRInputFeatureTypeRotation, kUnityXRInputFeatureUsageCenterEyeRotation);
6469
if (hasMultipleViews)
6570
{
6671
input.DeviceDefinition_AddFeatureWithUsage(definition, "left eye position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageLeftEyePosition);
@@ -96,25 +101,32 @@ UnitySubsystemErrorCode WebXRTrackingProvider::UpdateDeviceState(UnityXRInternal
96101
if (hasMultipleViews)
97102
{
98103
// Left pose
99-
input.DeviceState_SetAxis3DValue(state, 2, position);
100-
input.DeviceState_SetRotationValue(state, 3, rotation);
104+
input.DeviceState_SetAxis3DValue(state, 6, position);
105+
input.DeviceState_SetRotationValue(state, 7, rotation);
101106

102107
UnityXRVector3 rightPosition;
103108
rightPosition.x = *(m_ViewsDataArray + start + 3);
104109
rightPosition.y = *(m_ViewsDataArray + start + 4);
105110
rightPosition.z = *(m_ViewsDataArray + start + 5);
106111
// Right pose
107-
input.DeviceState_SetAxis3DValue(state, 4, position);
108-
input.DeviceState_SetRotationValue(state, 5, rotation);
112+
input.DeviceState_SetAxis3DValue(state, 8, position);
113+
input.DeviceState_SetRotationValue(state, 9, rotation);
109114

110115
// Update center pose
111116
position.x = 0.5f * (position.x + rightPosition.x);
112117
position.y = 0.5f * (position.y + rightPosition.y);
113118
position.z = 0.5f * (position.z + rightPosition.z);
114119
}
115120
// Center pose
116-
input.DeviceState_SetAxis3DValue(state, 0, position);
117-
input.DeviceState_SetRotationValue(state, 1, rotation);
121+
input.DeviceState_SetAxis3DValue(state, 2, position);
122+
input.DeviceState_SetRotationValue(state, 3, rotation);
123+
// Device pose
124+
input.DeviceState_SetAxis3DValue(state, 4, position);
125+
input.DeviceState_SetRotationValue(state, 5, rotation);
126+
127+
// Tracking
128+
input.DeviceState_SetBinaryValue(state, 0, true);
129+
input.DeviceState_SetDiscreteStateValue(state, 1, 3);
118130

119131
return kUnitySubsystemErrorCodeSuccess;
120132
}
@@ -217,5 +229,5 @@ UnitySubsystemErrorCode Load_Input(WebXRProviderContext &ctx)
217229
delete ctx.trackingProvider;
218230
};
219231

220-
return ctx.input->RegisterLifecycleProvider("WebXR Export", "WebXR HMD", &inputLifecycleHandler);
232+
return ctx.input->RegisterLifecycleProvider("WebXR Export", "WebXR Tracked Display", &inputLifecycleHandler);
221233
}

Packages/webxr/Runtime/UnitySubsystemsManifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"inputs": [
1313
{
14-
"id": "WebXR HMD"
14+
"id": "WebXR Tracked Display"
1515
}
1616
]
1717
}

Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override bool Initialize()
4747
public void StartEssentialSubsystems()
4848
{
4949
CreateSubsystem<XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(displaySubsystemDescriptors, "WebXR Display");
50-
CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(inputSubsystemDescriptors, "WebXR HMD");
50+
CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(inputSubsystemDescriptors, "WebXR Tracked Display");
5151
XRDisplaySubsystem.Start();
5252
XRInputSubsystem.Start();
5353
// TODO: Enable Single-Pass rendering

0 commit comments

Comments
 (0)