Skip to content

Commit

Permalink
Renamed WebXR HMD to WebXR Tracked Display and fixed its mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
De-Panther committed Feb 17, 2024
1 parent ba7feab commit ac291d5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 25 deletions.
1 change: 1 addition & 0 deletions Packages/webxr-interactions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebXRTrackedDisplay>(
matches: new InputDeviceMatcher()
.WithInterface(XRUtilities.InterfaceMatchAnyVersion)
.WithProduct("WebXR Tracked Display"));
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void InitializeInPlayer() { }
}

[Preserve]
public struct WebXRControllerState : IInputStateTypeInfo
{
Expand Down Expand Up @@ -158,7 +177,10 @@ public class WebXRController : XRControllerWithRumble

static WebXRController()
{
InputSystem.RegisterLayout<WebXRController>();
InputSystem.RegisterLayout<WebXRController>(
matches: new InputDeviceMatcher()
.WithInterface(XRUtilities.InterfaceMatchAnyVersion)
.WithProduct("WebXR Controller"));
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,9 +70,7 @@ private void Awake()
return;
}
initialized = true;
InputSystem.RegisterLayout<WebXRController>(
matches: new InputDeviceMatcher()
.WithInterface("WebXRController"));

#if XR_HANDS_1_1_OR_NEWER
var descriptors = new List<XRHandSubsystemDescriptor>();
SubsystemManager.GetSubsystemDescriptors(descriptors);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Packages/webxr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 22 additions & 10 deletions Packages/webxr/Runtime/Plugins/WebGL/WebXRTrackingProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -96,25 +101,32 @@ 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);
position.y = 0.5f * (position.y + rightPosition.y);
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;
}
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion Packages/webxr/Runtime/UnitySubsystemsManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"inputs": [
{
"id": "WebXR HMD"
"id": "WebXR Tracked Display"
}
]
}
2 changes: 1 addition & 1 deletion Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override bool Initialize()
public void StartEssentialSubsystems()
{
CreateSubsystem<XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(displaySubsystemDescriptors, "WebXR Display");
CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(inputSubsystemDescriptors, "WebXR HMD");
CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(inputSubsystemDescriptors, "WebXR Tracked Display");
XRDisplaySubsystem.Start();
XRInputSubsystem.Start();
// TODO: Enable Single-Pass rendering
Expand Down

0 comments on commit ac291d5

Please sign in to comment.