Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Feature/controller mapping refactor (#67)
Browse files Browse the repository at this point in the history
* updated lumin controller data provider

* added controller data provider reference to the controller

* updated references

* updated profile reference

* updated references

* Added default controller definitions

* removed redundant action assignments in mappings

* updated references

* added axis processor check

* Fixed inspector

* updated controller instance creation

* added a default constructor

* fixed TryRenderControllerModel call

* removed unused reference

* removed asset menu

* Remove obsolete SetupDefaultInteractions (#59)

* removed reference to input processor

* updated reference to camera rig

* updated platform flag to only be true on device

If we want any modules to run in the editor then we need to flip that flag

* updated hand inspector

* Added Lumin camera data provider

* updated lumin platform definition

* updated icon

* Added default lumin camera data provider profile

* reverted name change

* Updated constructors for data providers

* Added service parent reference

* cleaned up referenece

* updated nearclip distance

* Change requests for controller provider inspectors (#63)

* Update indent levels for Lumin settings

* Cache GUIContent in OnEnable

* Remove blank line

* Use static readonly

* updated lumin camera settings

* updated lumin camera data provider

* only reset local positions

Co-authored-by: Dino Fejzagic <dino.f@live.de>
  • Loading branch information
StephenHodgson and FejZa authored Apr 26, 2020
1 parent 2aa0ca0 commit c0b6210
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 125 deletions.
38 changes: 18 additions & 20 deletions Controllers/LuminController.cs
Original file line number Diff line number Diff line change
@@ -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() { }

/// <inheritdoc />
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)
{
}

/// <inheritdoc />
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),
};

/// <inheritdoc />
Expand All @@ -45,12 +48,6 @@ public LuminController(IMixedRealityControllerDataProvider controllerDataProvide
/// <inheritdoc />
public override MixedRealityInteractionMapping[] DefaultRightHandedInteractions => DefaultInteractions;

/// <inheritdoc />
public override void SetupDefaultInteractions(Handedness controllerHandedness)
{
AssignControllerMappings(DefaultInteractions);
}

#if PLATFORM_LUMIN

internal MLInputController MlControllerReference { get; set; }
Expand Down Expand Up @@ -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:
Expand Down
27 changes: 12 additions & 15 deletions Controllers/LuminControllerDataProvider.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,7 +22,7 @@ namespace XRTK.Lumin.Controllers
public class LuminControllerDataProvider : BaseControllerDataProvider
{
/// <inheritdoc />
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)
{
}
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 7 additions & 12 deletions Controllers/LuminHandControllerDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 27 additions & 12 deletions Inspectors/LuminHandControllerDataProviderProfileInspector.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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
}
14 changes: 0 additions & 14 deletions Inspectors/LuminMotionControllerMappingProfileInspector.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Inspectors/LuminMotionControllerMappingProfileInspector.cs.meta

This file was deleted.

21 changes: 21 additions & 0 deletions Profiles/LuminControllerDataProviderProfile.cs
Original file line number Diff line number Diff line change
@@ -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)
};
}
}
}
4 changes: 0 additions & 4 deletions Profiles/LuminHandControllerDataProviderProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 0 additions & 36 deletions Profiles/LuminMotionControllerMappingProfile.cs

This file was deleted.

2 changes: 1 addition & 1 deletion SpatialObservers/LuminSpatialMeshObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0b6210

Please sign in to comment.