diff --git a/Controllers/LuminController.cs b/Controllers/LuminController.cs index c6377ffc..a997149e 100644 --- a/Controllers/LuminController.cs +++ b/Controllers/LuminController.cs @@ -1,42 +1,45 @@ // Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using XRTK.Definitions.Controllers; using XRTK.Definitions.Devices; -using XRTK.Definitions.InputSystem; using XRTK.Definitions.Utilities; -using XRTK.Interfaces.InputSystem; using XRTK.Interfaces.Providers.Controllers; using XRTK.Providers.Controllers; #if PLATFORM_LUMIN + using UnityEngine; using UnityEngine.XR.MagicLeap; using XRTK.Extensions; using XRTK.Services; + #endif namespace XRTK.Lumin.Controllers { public class LuminController : BaseController { + public LuminController() : base() { } + /// - public LuminController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) - : base(controllerDataProvider, trackingState, controllerHandedness, inputSource, interactions) + public LuminController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile) + : base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile) { } /// public override MixedRealityInteractionMapping[] DefaultInteractions => new[] { - new MixedRealityInteractionMapping(0, "Spatial Pointer", AxisType.SixDof, DeviceInputType.SpatialPointer, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(1, "Trigger Position", AxisType.SingleAxis, DeviceInputType.Trigger, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(2, "Trigger Touch", AxisType.Digital, DeviceInputType.TriggerTouch, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(3, "Trigger Press (Select)", AxisType.Digital, DeviceInputType.Select, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(4, "Bumper Press", AxisType.Digital, DeviceInputType.ButtonPress, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(5, "Home Press", AxisType.Digital, DeviceInputType.ButtonPress, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(6, "Touchpad Position", AxisType.DualAxis, DeviceInputType.Touchpad, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(7, "Touchpad Press", AxisType.SingleAxis, DeviceInputType.TouchpadPress, MixedRealityInputAction.None), - new MixedRealityInteractionMapping(8, "Touchpad Touch", AxisType.SingleAxis, DeviceInputType.TouchpadTouch, MixedRealityInputAction.None), + new MixedRealityInteractionMapping("Spatial Pointer", AxisType.SixDof, DeviceInputType.SpatialPointer), + new MixedRealityInteractionMapping("Trigger Position", AxisType.SingleAxis, DeviceInputType.Trigger), + new MixedRealityInteractionMapping("Trigger Touch", AxisType.Digital, DeviceInputType.TriggerTouch), + new MixedRealityInteractionMapping("Trigger Press (Select)", AxisType.Digital, DeviceInputType.Select), + new MixedRealityInteractionMapping("Bumper Press", AxisType.Digital, DeviceInputType.ButtonPress), + new MixedRealityInteractionMapping("Home Press", AxisType.Digital, DeviceInputType.ButtonPress), + new MixedRealityInteractionMapping("Touchpad Position", AxisType.DualAxis, DeviceInputType.Touchpad), + new MixedRealityInteractionMapping("Touchpad Press", AxisType.SingleAxis, DeviceInputType.TouchpadPress), + new MixedRealityInteractionMapping("Touchpad Touch", AxisType.SingleAxis, DeviceInputType.TouchpadTouch), }; /// @@ -45,12 +48,6 @@ public LuminController(IMixedRealityControllerDataProvider controllerDataProvide /// public override MixedRealityInteractionMapping[] DefaultRightHandedInteractions => DefaultInteractions; - /// - public override void SetupDefaultInteractions(Handedness controllerHandedness) - { - AssignControllerMappings(DefaultInteractions); - } - #if PLATFORM_LUMIN internal MLInputController MlControllerReference { get; set; } @@ -201,7 +198,8 @@ private void UpdateSingleAxisData(MixedRealityInteractionMapping interactionMapp case DeviceInputType.Trigger: case DeviceInputType.TriggerPress: case DeviceInputType.TouchpadPress: - interactionMapping.BoolData = interactionMapping.FloatData.Equals(interactionMapping.InvertXAxis ? -1f : 1f); + interactionMapping.BoolData = interactionMapping.FloatData.Approximately(1f, 0.001f) || + interactionMapping.FloatData.Approximately(-1f, 0.001f); break; case DeviceInputType.TriggerTouch: case DeviceInputType.TouchpadTouch: diff --git a/Controllers/LuminControllerDataProvider.cs b/Controllers/LuminControllerDataProvider.cs index 5ac22acb..e5829c13 100644 --- a/Controllers/LuminControllerDataProvider.cs +++ b/Controllers/LuminControllerDataProvider.cs @@ -1,12 +1,13 @@ // Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using XRTK.Definitions.Controllers; +using XRTK.Lumin.Profiles; using XRTK.Interfaces.InputSystem; using XRTK.Providers.Controllers; #if PLATFORM_LUMIN +using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.MagicLeap; @@ -21,7 +22,7 @@ namespace XRTK.Lumin.Controllers public class LuminControllerDataProvider : BaseControllerDataProvider { /// - public LuminControllerDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile, IMixedRealityInputSystem parentService) + public LuminControllerDataProvider(string name, uint priority, LuminControllerDataProviderProfile profile, IMixedRealityInputSystem parentService) : base(name, priority, profile, parentService) { } @@ -110,35 +111,31 @@ private LuminController GetController(byte controllerId, bool addController = tr if (mlController.Type == MLInputControllerType.None) { return null; } - var controllingHand = Handedness.Any; + var handedness = Handedness.Any; if (mlController.Type == MLInputControllerType.Control) { switch (mlController.Hand) { case MLInput.Hand.Left: - controllingHand = Handedness.Left; + handedness = Handedness.Left; break; case MLInput.Hand.Right: - controllingHand = Handedness.Right; + handedness = Handedness.Right; break; } } - var pointers = mlController.Type == MLInputControllerType.Control ? RequestPointers(typeof(LuminController), controllingHand) : null; - var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"Lumin Controller {controllingHand}", pointers); - var detectedController = new LuminController(this, TrackingState.NotTracked, controllingHand, inputSource); + LuminController detectedController; - if (!detectedController.SetupConfiguration(typeof(LuminController))) + try { - // Controller failed to be setup correctly. - // Return null so we don't raise the source detected. - return null; + detectedController = new LuminController(this, TrackingState.NotTracked, handedness, GetControllerMappingProfile(typeof(LuminController), handedness)); } - - for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++) + catch (Exception e) { - detectedController.InputSource.Pointers[i].Controller = detectedController; + Debug.LogError($"Failed to create {nameof(LuminController)}!\n{e}"); + return null; } detectedController.MlControllerReference = mlController; diff --git a/Controllers/LuminHandControllerDataProvider.cs b/Controllers/LuminHandControllerDataProvider.cs index 75eaed4b..401b44e8 100644 --- a/Controllers/LuminHandControllerDataProvider.cs +++ b/Controllers/LuminHandControllerDataProvider.cs @@ -112,24 +112,19 @@ private MixedRealityHandController GetOrAddController(Handedness handedness) return existingController; } - var controllerType = typeof(MixedRealityHandController); - var pointers = RequestPointers(controllerType, handedness, true); - var inputSource = MixedRealityToolkit.InputSystem.RequestNewGenericInputSource($"{handedness} Hand Controller", pointers); - var detectedController = new MixedRealityHandController(this, TrackingState.Tracked, handedness, inputSource); + MixedRealityHandController detectedController; - if (!detectedController.SetupConfiguration(controllerType)) + try { - // Controller failed to be setup correctly. - // Return null so we don't raise the source detected. - return null; + detectedController = new MixedRealityHandController(this, TrackingState.Tracked, handedness, GetControllerMappingProfile(typeof(MixedRealityHandController), handedness)); } - - for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++) + catch (Exception e) { - detectedController.InputSource.Pointers[i].Controller = detectedController; + Debug.LogError($"Failed to create {nameof(MixedRealityHandController)}!\n{e}"); + return null; } - detectedController.TryRenderControllerModel(controllerType); + detectedController.TryRenderControllerModel(); activeControllers.Add(handedness, detectedController); AddController(detectedController); diff --git a/Inspectors/LuminHandControllerDataProviderProfileInspector.cs b/Inspectors/LuminHandControllerDataProviderProfileInspector.cs index f6869a0d..f90685be 100644 --- a/Inspectors/LuminHandControllerDataProviderProfileInspector.cs +++ b/Inspectors/LuminHandControllerDataProviderProfileInspector.cs @@ -1,13 +1,15 @@ // Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -#if PLATFORM_LUMIN - using UnityEditor; using UnityEngine; +using XRTK.Inspectors.Extensions; using XRTK.Inspectors.Profiles.InputSystem.Controllers; using XRTK.Lumin.Profiles; + +#if PLATFORM_LUMIN using UnityEngine.XR.MagicLeap; +#endif // PLATFORM_LUMIN namespace XRTK.Lumin.Inspectors { @@ -17,36 +19,49 @@ public class LuminHandControllerDataProviderProfileInspector : BaseMixedRealityH private SerializedProperty poseFilterLevel; private SerializedProperty keyPointFilterLevel; + private static readonly GUIContent handTrackingFoldoutHeader = new GUIContent("Lumin Hand Tracking Settings"); + +#if PLATFORM_LUMIN private GUIContent keyPointContent; private GUIContent poseFilterContent; +#endif // PLATFORM_LUMIN + + private bool showLuminHandTrackingSettings = true; protected override void OnEnable() { base.OnEnable(); keyPointFilterLevel = serializedObject.FindProperty(nameof(keyPointFilterLevel)); - keyPointContent = new GUIContent(keyPointFilterLevel.displayName, keyPointFilterLevel.tooltip); poseFilterLevel = serializedObject.FindProperty(nameof(poseFilterLevel)); + +#if PLATFORM_LUMIN + keyPointContent = new GUIContent(keyPointFilterLevel.displayName, keyPointFilterLevel.tooltip); poseFilterContent = new GUIContent(poseFilterLevel.displayName, poseFilterLevel.tooltip); +#endif // PLATFORM_LUMIN } public override void OnInspectorGUI() { - RenderHeader(); - - EditorGUILayout.LabelField("Lumin Hand Controller Data Provider Settings", EditorStyles.boldLabel); - base.OnInspectorGUI(); - serializedObject.Update(); - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Lumin Hand Settings"); + serializedObject.Update(); + showLuminHandTrackingSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showLuminHandTrackingSettings, handTrackingFoldoutHeader, true); + if (showLuminHandTrackingSettings) + { + EditorGUI.indentLevel++; +#if PLATFORM_LUMIN keyPointFilterLevel.intValue = (int)(MLKeyPointFilterLevel)EditorGUILayout.EnumPopup(keyPointContent, (MLKeyPointFilterLevel)keyPointFilterLevel.intValue); poseFilterLevel.intValue = (int)(MLPoseFilterLevel)EditorGUILayout.EnumPopup(poseFilterContent, (MLPoseFilterLevel)poseFilterLevel.intValue); +#else + EditorGUILayout.PropertyField(keyPointFilterLevel); + EditorGUILayout.PropertyField(poseFilterLevel); +#endif // PLATFORM_LUMIN + EditorGUI.indentLevel--; + } serializedObject.ApplyModifiedProperties(); } } -} -#endif // PLATFORM_LUMIN +} \ No newline at end of file diff --git a/Inspectors/LuminMotionControllerMappingProfileInspector.cs b/Inspectors/LuminMotionControllerMappingProfileInspector.cs deleted file mode 100644 index b8ed1053..00000000 --- a/Inspectors/LuminMotionControllerMappingProfileInspector.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) XRTK. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using UnityEditor; -using XRTK.Inspectors.Profiles.InputSystem.Controllers; -using XRTK.Lumin.Profiles; - -namespace XRTK.Lumin.Inspectors -{ - [CustomEditor(typeof(LuminMotionControllerMappingProfile))] - public class LuminMotionControllerMappingProfileInspector : BaseMixedRealityControllerMappingProfileInspector - { - } -} \ No newline at end of file diff --git a/Inspectors/LuminMotionControllerMappingProfileInspector.cs.meta b/Inspectors/LuminMotionControllerMappingProfileInspector.cs.meta deleted file mode 100644 index aa0a263d..00000000 --- a/Inspectors/LuminMotionControllerMappingProfileInspector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9c124191003df5642906d0a9f2882a4e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {fileID: 2800000, guid: 6e2e9d716bbb4d8382bd53f11996b90e, type: 3} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Profiles/LuminControllerDataProviderProfile.cs b/Profiles/LuminControllerDataProviderProfile.cs new file mode 100644 index 00000000..9d4e1101 --- /dev/null +++ b/Profiles/LuminControllerDataProviderProfile.cs @@ -0,0 +1,21 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using XRTK.Definitions.Controllers; +using XRTK.Definitions.Utilities; +using XRTK.Lumin.Controllers; + +namespace XRTK.Lumin.Profiles +{ + public class LuminControllerDataProviderProfile : BaseMixedRealityControllerDataProviderProfile + { + public override ControllerDefinition[] GetDefaultControllerOptions() + { + return new[] + { + new ControllerDefinition(typeof(LuminController), Handedness.Left), + new ControllerDefinition(typeof(LuminController), Handedness.Right) + }; + } + } +} \ No newline at end of file diff --git a/Profiles/LuminMotionControllerMappingProfile.cs.meta b/Profiles/LuminControllerDataProviderProfile.cs.meta similarity index 100% rename from Profiles/LuminMotionControllerMappingProfile.cs.meta rename to Profiles/LuminControllerDataProviderProfile.cs.meta diff --git a/Profiles/LuminHandControllerDataProviderProfile.cs b/Profiles/LuminHandControllerDataProviderProfile.cs index 0e0009bc..aaa0b1f4 100644 --- a/Profiles/LuminHandControllerDataProviderProfile.cs +++ b/Profiles/LuminHandControllerDataProviderProfile.cs @@ -3,15 +3,11 @@ using UnityEngine; using XRTK.Definitions.Controllers.Hands; -using XRTK.Definitions.Utilities; namespace XRTK.Lumin.Profiles { - [CreateAssetMenu(menuName = "Mixed Reality Toolkit/Input System/Controller Data Providers/Lumin Hand", fileName = "LuminHandControllerDataProviderProfile", order = (int)CreateProfileMenuItemIndices.Input)] public class LuminHandControllerDataProviderProfile : BaseHandControllerDataProviderProfile { - [Header("Lumin Platform Settings")] - [SerializeField] [Tooltip("Configured level for keypoints filtering of keypoints and hand centers.")] private int keyPointFilterLevel = 0; diff --git a/Profiles/LuminMotionControllerMappingProfile.cs b/Profiles/LuminMotionControllerMappingProfile.cs deleted file mode 100644 index df4e63bd..00000000 --- a/Profiles/LuminMotionControllerMappingProfile.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) XRTK. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using UnityEngine; -using XRTK.Definitions.Devices; -using XRTK.Definitions.Utilities; -using XRTK.Lumin.Controllers; -using XRTK.Definitions.Controllers; -using XRTK.Providers.Controllers; - -namespace XRTK.Lumin.Profiles -{ - [CreateAssetMenu(menuName = "Mixed Reality Toolkit/Input System/Controller Mappings/Lumin Controller Mapping Profile", fileName = "LuminControllerMappingProfile")] - public class LuminMotionControllerMappingProfile : BaseMixedRealityControllerMappingProfile - { - /// - public override SupportedControllerType ControllerType => SupportedControllerType.Lumin; - - /// - public override string TexturePath => $"{base.TexturePath}LuminController"; - - protected override void Awake() - { - if (!HasSetupDefaults) - { - ControllerMappings = new[] - { - new MixedRealityControllerMapping("Lumin Motion Controller Left", typeof(LuminController), Handedness.Left), - new MixedRealityControllerMapping("Lumin Motion Controller Right", typeof(LuminController), Handedness.Right), - }; - } - - base.Awake(); - } - } -} diff --git a/SpatialObservers/LuminSpatialMeshObserver.cs b/SpatialObservers/LuminSpatialMeshObserver.cs index a0b3eef3..22d9ae63 100644 --- a/SpatialObservers/LuminSpatialMeshObserver.cs +++ b/SpatialObservers/LuminSpatialMeshObserver.cs @@ -14,7 +14,7 @@ using UnityEngine.XR.MagicLeap; using XRTK.Definitions.SpatialAwarenessSystem; using XRTK.Services; -using XRTK.Utilities; + #endif // PLATFORM_LUMIN namespace XRTK.Lumin.SpatialObservers