From ac291d5d605c5fbede3d2030ac676a5fc313a1d0 Mon Sep 17 00:00:00 2001 From: De-Panther Date: Sat, 17 Feb 2024 04:46:10 +0200 Subject: [PATCH] Renamed WebXR HMD to WebXR Tracked Display and fixed its mapping --- Packages/webxr-interactions/CHANGELOG.md | 1 + .../Runtime/InputSystem/WebXRInputDevices.cs | 24 +++++++++++++- .../Runtime/InputSystem/WebXRInputSystem.cs | 17 +++------- Packages/webxr/CHANGELOG.md | 2 ++ .../Plugins/WebGL/WebXRTrackingProvider.cpp | 32 +++++++++++++------ .../Runtime/UnitySubsystemsManifest.json | 2 +- .../webxr/Runtime/XRPlugin/WebXRLoader.cs | 2 +- 7 files changed, 55 insertions(+), 25 deletions(-) diff --git a/Packages/webxr-interactions/CHANGELOG.md b/Packages/webxr-interactions/CHANGELOG.md index 5641829c..ff5ad59d 100644 --- a/Packages/webxr-interactions/CHANGELOG.md +++ b/Packages/webxr-interactions/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - SceneHitTest now updates the pose of the originTransform instead of WebXRManager transform. +- Mapping of WebXR Tracked Display device. ## [0.20.0] - 2023-12-18 ### Added diff --git a/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputDevices.cs b/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputDevices.cs index aa108355..c076ee54 100644 --- a/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputDevices.cs +++ b/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputDevices.cs @@ -11,6 +11,25 @@ namespace WebXR.InputSystem { using InputSystem = UnityEngine.InputSystem.InputSystem; + +#if UNITY_EDITOR + [UnityEditor.InitializeOnLoad] +#endif + [Preserve, InputControlLayout(displayName = "WebXR Tracked Display")] + internal class WebXRTrackedDisplay : XRHMD + { + static WebXRTrackedDisplay() + { + InputSystem.RegisterLayout( + matches: new InputDeviceMatcher() + .WithInterface(XRUtilities.InterfaceMatchAnyVersion) + .WithProduct("WebXR Tracked Display")); + } + + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] + private static void InitializeInPlayer() { } + } + [Preserve] public struct WebXRControllerState : IInputStateTypeInfo { @@ -158,7 +177,10 @@ public class WebXRController : XRControllerWithRumble static WebXRController() { - InputSystem.RegisterLayout(); + InputSystem.RegisterLayout( + matches: new InputDeviceMatcher() + .WithInterface(XRUtilities.InterfaceMatchAnyVersion) + .WithProduct("WebXR Controller")); } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] diff --git a/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs b/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs index 29108910..178f2b9f 100644 --- a/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs +++ b/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs @@ -4,6 +4,7 @@ using UnityEngine.InputSystem; using UnityEngine.InputSystem.Layouts; using UnityEngine.InputSystem.LowLevel; + #if XR_HANDS_1_1_OR_NEWER using System.Collections; using System.Collections.Generic; @@ -69,9 +70,7 @@ private void Awake() return; } initialized = true; - InputSystem.RegisterLayout( - matches: new InputDeviceMatcher() - .WithInterface("WebXRController")); + #if XR_HANDS_1_1_OR_NEWER var descriptors = new List(); SubsystemManager.GetSubsystemDescriptors(descriptors); @@ -346,18 +345,12 @@ private static IEnumerator RemoveDeviceAfterFrame(UnityEngine.InputSystem.InputD private static WebXRController GetWebXRController(int hand) { - string product = "WebXRController Left"; - string usage = "LeftHand"; - if (hand == 2) - { - product = "WebXRController Right"; - usage = "RightHand"; - } + string usage = hand == 2 ? "RightHand" : "LeftHand"; var device = InputSystem.AddDevice( new InputDeviceDescription { - interfaceName = "WebXRController", - product = product + interfaceName = "XRInput", + product = "WebXR Controller" }); InputSystem.AddDeviceUsage(device, usage); return (WebXRController)device; diff --git a/Packages/webxr/CHANGELOG.md b/Packages/webxr/CHANGELOG.md index 83762c6d..a82928b6 100644 --- a/Packages/webxr/CHANGELOG.md +++ b/Packages/webxr/CHANGELOG.md @@ -11,9 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - XR Hand pinch is now detected manually instead of relying on system select event, to support Apple Vision Pro. +- Renamed WebXR HMD to WebXR Tracked Display. ### Fixed - Errors of Module._malloc and Module._free are not functions. +- Mapping of WebXR Tracked Display device. ## [0.21.0] - 2024-01-17 ### Added diff --git a/Packages/webxr/Runtime/Plugins/WebGL/WebXRTrackingProvider.cpp b/Packages/webxr/Runtime/Plugins/WebGL/WebXRTrackingProvider.cpp index bd8c8e90..58797188 100644 --- a/Packages/webxr/Runtime/Plugins/WebGL/WebXRTrackingProvider.cpp +++ b/Packages/webxr/Runtime/Plugins/WebGL/WebXRTrackingProvider.cpp @@ -55,12 +55,17 @@ UnitySubsystemErrorCode WebXRTrackingProvider::FillDeviceDefinition(UnityXRInter { // Fill in your connected device information here when requested. Used to create customized device states. auto &input = *m_Ctx.input; - input.DeviceDefinition_SetName(definition, "WebXRHMD"); + input.DeviceDefinition_SetName(definition, "WebXR Tracked Display"); input.DeviceDefinition_SetCharacteristics(definition, (UnityXRInputDeviceCharacteristics)(kUnityXRInputDeviceCharacteristicsHeadMounted | kUnityXRInputDeviceCharacteristicsTrackedDevice)); input.DeviceDefinition_SetManufacturer(definition, "WebXR"); - input.DeviceDefinition_AddFeatureWithUsage(definition, "head position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageCenterEyePosition); - input.DeviceDefinition_AddFeatureWithUsage(definition, "head rotation", kUnityXRInputFeatureTypeRotation, kUnityXRInputFeatureUsageCenterEyeRotation); + input.DeviceDefinition_AddFeatureWithUsage(definition, "is tracked", kUnityXRInputFeatureTypeBinary, kUnityXRInputFeatureUsageIsTracked); + input.DeviceDefinition_AddFeatureWithUsage(definition, "tracking state", kUnityXRInputFeatureTypeDiscreteStates, kUnityXRInputFeatureUsageTrackingState); + + input.DeviceDefinition_AddFeatureWithUsage(definition, "device position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageDevicePosition); + input.DeviceDefinition_AddFeatureWithUsage(definition, "device rotation", kUnityXRInputFeatureTypeRotation, kUnityXRInputFeatureUsageDeviceRotation); + input.DeviceDefinition_AddFeatureWithUsage(definition, "center eye position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageCenterEyePosition); + input.DeviceDefinition_AddFeatureWithUsage(definition, "center eye rotation", kUnityXRInputFeatureTypeRotation, kUnityXRInputFeatureUsageCenterEyeRotation); if (hasMultipleViews) { input.DeviceDefinition_AddFeatureWithUsage(definition, "left eye position", kUnityXRInputFeatureTypeAxis3D, kUnityXRInputFeatureUsageLeftEyePosition); @@ -96,16 +101,16 @@ UnitySubsystemErrorCode WebXRTrackingProvider::UpdateDeviceState(UnityXRInternal if (hasMultipleViews) { // Left pose - input.DeviceState_SetAxis3DValue(state, 2, position); - input.DeviceState_SetRotationValue(state, 3, rotation); + input.DeviceState_SetAxis3DValue(state, 6, position); + input.DeviceState_SetRotationValue(state, 7, rotation); UnityXRVector3 rightPosition; rightPosition.x = *(m_ViewsDataArray + start + 3); rightPosition.y = *(m_ViewsDataArray + start + 4); rightPosition.z = *(m_ViewsDataArray + start + 5); // Right pose - input.DeviceState_SetAxis3DValue(state, 4, position); - input.DeviceState_SetRotationValue(state, 5, rotation); + input.DeviceState_SetAxis3DValue(state, 8, position); + input.DeviceState_SetRotationValue(state, 9, rotation); // Update center pose position.x = 0.5f * (position.x + rightPosition.x); @@ -113,8 +118,15 @@ UnitySubsystemErrorCode WebXRTrackingProvider::UpdateDeviceState(UnityXRInternal position.z = 0.5f * (position.z + rightPosition.z); } // Center pose - input.DeviceState_SetAxis3DValue(state, 0, position); - input.DeviceState_SetRotationValue(state, 1, rotation); + input.DeviceState_SetAxis3DValue(state, 2, position); + input.DeviceState_SetRotationValue(state, 3, rotation); + // Device pose + input.DeviceState_SetAxis3DValue(state, 4, position); + input.DeviceState_SetRotationValue(state, 5, rotation); + + // Tracking + input.DeviceState_SetBinaryValue(state, 0, true); + input.DeviceState_SetDiscreteStateValue(state, 1, 3); return kUnitySubsystemErrorCodeSuccess; } @@ -217,5 +229,5 @@ UnitySubsystemErrorCode Load_Input(WebXRProviderContext &ctx) delete ctx.trackingProvider; }; - return ctx.input->RegisterLifecycleProvider("WebXR Export", "WebXR HMD", &inputLifecycleHandler); + return ctx.input->RegisterLifecycleProvider("WebXR Export", "WebXR Tracked Display", &inputLifecycleHandler); } \ No newline at end of file diff --git a/Packages/webxr/Runtime/UnitySubsystemsManifest.json b/Packages/webxr/Runtime/UnitySubsystemsManifest.json index 676a6694..fa949a61 100644 --- a/Packages/webxr/Runtime/UnitySubsystemsManifest.json +++ b/Packages/webxr/Runtime/UnitySubsystemsManifest.json @@ -11,7 +11,7 @@ ], "inputs": [ { - "id": "WebXR HMD" + "id": "WebXR Tracked Display" } ] } diff --git a/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs b/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs index 90f83c44..ff342204 100644 --- a/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs +++ b/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs @@ -47,7 +47,7 @@ public override bool Initialize() public void StartEssentialSubsystems() { CreateSubsystem(displaySubsystemDescriptors, "WebXR Display"); - CreateSubsystem(inputSubsystemDescriptors, "WebXR HMD"); + CreateSubsystem(inputSubsystemDescriptors, "WebXR Tracked Display"); XRDisplaySubsystem.Start(); XRInputSubsystem.Start(); // TODO: Enable Single-Pass rendering