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 (#71)
Browse files Browse the repository at this point in the history
* updated wmr controller data provider

* removed commented out class

* added controller data provider reference to the controller

* updated references

* fixed references

* Added default controller definitions

* updated the controller data provider inspector

fixed naming for controller definition

* updated hand data provider profile inspector

* removed redundant inspector

* cleaned up the controller interaction mappings a bit

* updated references

* updated controller instance creation

* added default constructor

* updated TryRenderController method

* removed asset menu

* fixed compiler error

* Remove obsolete SetupDefaultIntreactions (#65)

* updated reference

* added WMR Camera Data Provider

* updated WMR Camera Data Provider

* updated camera rig reference

* updated icon

* moved WMR Camera data provider into correct file location

* updated data provider constructors

* added service parent reference

* Change requests for controller provider inspectors (#67)

* Update indent levels for WMR settings

* Cache GUIContent

* Added rig reset override

* reverted changes

* removed unused reference

* added camera profile

* Updated windows controller type name to get the controller textures to show up correctly based on the type name

* fixed reference to renamed controller class

* fixed more type references

Co-authored-by: Dino Fejzagic <dino.f@live.de>
  • Loading branch information
StephenHodgson and FejZa committed Apr 26, 2020
1 parent e095036 commit 481fc30
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 191 deletions.
41 changes: 18 additions & 23 deletions Controllers/WindowsMixedRealityControllerDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using XRTK.WindowsMixedReality.Profiles;

#if UNITY_WSA
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.WSA.Input;
Expand All @@ -19,7 +20,6 @@
#endif // UNITY_WSA

#if WINDOWS_UWP
using System;
using Windows.ApplicationModel.Core;
using Windows.Perception;
using Windows.Storage.Streams;
Expand Down Expand Up @@ -387,57 +387,53 @@ protected override void OnDispose(bool finalizing)
/// <param name="interactionSource">Source State provided by the SDK</param>
/// <param name="addController">Should the Source be added as a controller if it isn't found?</param>
/// <returns>New or Existing Controller Input Source</returns>
private WindowsMixedRealityController GetController(InteractionSource interactionSource, bool addController = false)
private WindowsMixedRealityMotionController GetController(InteractionSource interactionSource, bool addController = false)
{
//If a device is already registered with the ID provided, just return it.
if (activeControllers.ContainsKey(interactionSource.id))
{
var controller = activeControllers[interactionSource.id] as WindowsMixedRealityController;
var controller = activeControllers[interactionSource.id] as WindowsMixedRealityMotionController;
Debug.Assert(controller != null);
return controller;
}

if (!addController) { return null; }

Handedness controllingHand;
Handedness handedness;

switch (interactionSource.handedness)
{
default:
controllingHand = Handedness.None;
handedness = Handedness.None;
break;
case InteractionSourceHandedness.Left:
controllingHand = Handedness.Left;
handedness = Handedness.Left;
break;
case InteractionSourceHandedness.Right:
controllingHand = Handedness.Right;
handedness = Handedness.Right;
break;
}

var pointers = interactionSource.supportsPointing ? RequestPointers(typeof(WindowsMixedRealityController), controllingHand) : null;
var nameModifier = controllingHand == Handedness.None ? interactionSource.kind.ToString() : controllingHand.ToString();
var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"Mixed Reality Controller {nameModifier}", pointers);
var detectedController = new WindowsMixedRealityController(this, TrackingState.NotApplicable, controllingHand, inputSource);
WindowsMixedRealityMotionController detectedController;

if (!detectedController.SetupConfiguration(typeof(WindowsMixedRealityController)))
try
{
detectedController = new WindowsMixedRealityMotionController(this, TrackingState.NotApplicable, handedness, GetControllerMappingProfile(typeof(WindowsMixedRealityMotionController), handedness));
}
catch (Exception e)
{
// Controller failed to be setup correctly.
// Return null so we don't raise the source detected.
Debug.LogError($"Failed to create {nameof(WindowsMixedRealityMotionController)}!\n{e}");
return null;
}

TryRenderControllerModel(interactionSource, detectedController);

for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++)
{
detectedController.InputSource.Pointers[i].Controller = detectedController;
}

activeControllers.Add(interactionSource.id, detectedController);
AddController(detectedController);
return detectedController;
}

private static async void TryRenderControllerModel(InteractionSource interactionSource, WindowsMixedRealityController controller)
private static async void TryRenderControllerModel(InteractionSource interactionSource, WindowsMixedRealityMotionController controller)
{
#if WINDOWS_UWP
if (!UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque) { return; }
Expand Down Expand Up @@ -481,11 +477,10 @@ async void DispatchedHandler()
Debug.LogError("Failed to load model data!");
}

// This really isn't an error, we actually can call TryRenderControllerModelAsync here.
await controller.TryRenderControllerModelAsync(typeof(WindowsMixedRealityController), glbModelData, interactionSource.kind == InteractionSourceKind.Hand);
await controller.TryRenderControllerModelAsync(glbModelData, interactionSource.kind == InteractionSourceKind.Hand);
}
#else
await controller.TryRenderControllerModelAsync(typeof(WindowsMixedRealityController), null, interactionSource.kind == InteractionSourceKind.Hand);
await controller.TryRenderControllerModelAsync(null, interactionSource.kind == InteractionSourceKind.Hand);
#endif // WINDOWS_UWP
}

Expand Down
27 changes: 12 additions & 15 deletions Controllers/WindowsMixedRealityHandControllerDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,25 @@ private bool TryGetController(Handedness handedness, out MixedRealityHandControl
private MixedRealityHandController CreateController(SpatialInteractionSource spatialInteractionSource)
{
// We are creating a new controller for the source, determine the type of controller to use.
Type controllerType = spatialInteractionSource.Kind.ToControllerType();
var controllerType = spatialInteractionSource.Kind.ToControllerType();

if (controllerType == null || controllerType != typeof(MixedRealityHandController))
{
// This data provider only cares about hands.
return null;
}

// Ready to create the controller instance.
var controllingHand = spatialInteractionSource.Handedness.ToHandedness();
var pointers = spatialInteractionSource.IsPointingSupported ? RequestPointers(controllerType, controllingHand, true) : null;
var nameModifier = controllingHand == Handedness.None ? spatialInteractionSource.Kind.ToString() : controllingHand.ToString();
var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"Mixed Reality Hand Controller {nameModifier}", pointers);
var detectedController = new MixedRealityHandController(this, TrackingState.NotApplicable, controllingHand, inputSource);
var handedness = spatialInteractionSource.Handedness.ToHandedness();

if (!detectedController.SetupConfiguration(controllerType))
MixedRealityHandController detectedController;

try
{
detectedController = new MixedRealityHandController(this, TrackingState.NotApplicable, handedness, GetControllerMappingProfile(typeof(MixedRealityHandController), handedness));
}
catch (Exception e)
{
// Controller failed to be setup correctly.
// Return null so we don't raise the source detected.
Debug.LogError($"Failed to create {nameof(MixedRealityHandController)}!\n{e}");
return null;
}

Expand All @@ -226,13 +226,10 @@ private MixedRealityHandController CreateController(SpatialInteractionSource spa

MixedRealityToolkit.InputSystem?.RaiseSourceDetected(detectedController.InputSource, detectedController);

if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.ControllerVisualizationProfile.RenderMotionControllers)
{
detectedController.TryRenderControllerModel(controllerType);
}
detectedController.TryRenderControllerModel();

AddController(detectedController);
activeControllers.Add(controllingHand, detectedController);
activeControllers.Add(handedness, detectedController);
return detectedController;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation. 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;

Expand All @@ -20,11 +19,13 @@ namespace XRTK.WindowsMixedReality.Controllers
/// <summary>
/// A Windows Mixed Reality Controller Instance.
/// </summary>
public class WindowsMixedRealityController : BaseController
public class WindowsMixedRealityMotionController : BaseController
{
public WindowsMixedRealityMotionController() : base() { }

/// <inheritdoc />
public WindowsMixedRealityController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(controllerDataProvider, trackingState, controllerHandedness, inputSource, interactions)
public WindowsMixedRealityMotionController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile)
: base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile)
{
}

Expand All @@ -34,18 +35,18 @@ public WindowsMixedRealityController(IMixedRealityControllerDataProvider control
/// <remarks>A single interaction mapping works for both left and right controllers.</remarks>
public override MixedRealityInteractionMapping[] DefaultInteractions => new[]
{
new MixedRealityInteractionMapping(0, "Spatial Pointer", AxisType.SixDof, DeviceInputType.SpatialPointer, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(1, "Spatial Grip", AxisType.SixDof, DeviceInputType.SpatialGrip, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(2, "Grip Press", AxisType.SingleAxis, DeviceInputType.TriggerPress, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(3, "Trigger Position", AxisType.SingleAxis, DeviceInputType.Trigger, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(4, "Trigger Touched", AxisType.Digital, DeviceInputType.TriggerTouch, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(5, "Trigger Press (Select)", AxisType.Digital, DeviceInputType.Select, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(6, "Touchpad Position", AxisType.DualAxis, DeviceInputType.Touchpad, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(7, "Touchpad Touch", AxisType.Digital, DeviceInputType.TouchpadTouch, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(8, "Touchpad Press", AxisType.Digital, DeviceInputType.TouchpadPress, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(9, "Menu Press", AxisType.Digital, DeviceInputType.Menu, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(10, "Thumbstick Position", AxisType.DualAxis, DeviceInputType.ThumbStick, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(11, "Thumbstick Press", AxisType.Digital, DeviceInputType.ThumbStickPress, MixedRealityInputAction.None),
new MixedRealityInteractionMapping("Spatial Pointer", AxisType.SixDof, DeviceInputType.SpatialPointer),
new MixedRealityInteractionMapping("Spatial Grip", AxisType.SixDof, DeviceInputType.SpatialGrip),
new MixedRealityInteractionMapping("Grip Press", AxisType.SingleAxis, DeviceInputType.TriggerPress),
new MixedRealityInteractionMapping("Trigger Position", AxisType.SingleAxis, DeviceInputType.Trigger),
new MixedRealityInteractionMapping("Trigger Touched", AxisType.Digital, DeviceInputType.TriggerTouch),
new MixedRealityInteractionMapping("Trigger Press (Select)", AxisType.Digital, DeviceInputType.Select),
new MixedRealityInteractionMapping("Touchpad Position", AxisType.DualAxis, DeviceInputType.Touchpad),
new MixedRealityInteractionMapping("Touchpad Touch", AxisType.Digital, DeviceInputType.TouchpadTouch),
new MixedRealityInteractionMapping("Touchpad Press", AxisType.Digital, DeviceInputType.TouchpadPress),
new MixedRealityInteractionMapping("Menu Press", AxisType.Digital, DeviceInputType.Menu),
new MixedRealityInteractionMapping("Thumbstick Position", AxisType.DualAxis, DeviceInputType.ThumbStick),
new MixedRealityInteractionMapping("Thumbstick Press", AxisType.Digital, DeviceInputType.ThumbStickPress),
};

/// <inheritdoc />
Expand All @@ -54,12 +55,6 @@ public WindowsMixedRealityController(IMixedRealityControllerDataProvider control
/// <inheritdoc />
public override MixedRealityInteractionMapping[] DefaultRightHandedInteractions => DefaultInteractions;

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

#if UNITY_WSA

/// <summary>
Expand Down Expand Up @@ -133,7 +128,7 @@ public void UpdateController(InteractionSourceState interactionSourceState)
UpdateMenuData(interactionSourceState, interactionMapping);
break;
default:
Debug.LogError($"Input [{interactionMapping.InputType}] is not handled for this controller [{GetType().Name}]");
Debug.LogError($"Input [{interactionMapping.Description}.{interactionMapping.InputType}] is not handled for this controller [{GetType().Name}]");
Enabled = false;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Extensions/SpatialInteractionSourceKindExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static Type ToControllerType(this SpatialInteractionSourceKind spatialInt
switch (spatialInteractionSourceKind)
{
case SpatialInteractionSourceKind.Controller:
return typeof(WindowsMixedRealityController);
return typeof(WindowsMixedRealityMotionController);
case SpatialInteractionSourceKind.Hand:
return typeof(MixedRealityHandController);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEditor;
using XRTK.Inspectors.Profiles;
using UnityEngine;
using XRTK.Inspectors.Extensions;
using XRTK.Inspectors.Profiles.InputSystem.Controllers;
using XRTK.WindowsMixedReality.Profiles;

namespace XRTK.WindowsMixedReality.Inspectors
{
[CustomEditor(typeof(WindowsMixedRealityControllerDataProviderProfile))]
public class WindowsMixedRealityControllerDataProviderProfileInspector : BaseMixedRealityProfileInspector
public class WindowsMixedRealityControllerDataProviderProfileInspector : BaseMixedRealityControllerDataProviderProfileInspector
{
private SerializedProperty manipulationGestures;
private SerializedProperty useRailsNavigation;
private SerializedProperty navigationGestures;
private SerializedProperty railsNavigationGestures;
private SerializedProperty windowsGestureAutoStart;

bool showGestureSettings = true;
private static readonly GUIContent gestureSettingsFoldoutHeader = new GUIContent("Windows Gesture Settings");

protected override void OnEnable()
{
base.OnEnable();
Expand All @@ -29,20 +34,20 @@ protected override void OnEnable()

public override void OnInspectorGUI()
{
RenderHeader();

EditorGUILayout.Space();
EditorGUILayout.LabelField("Windows Mixed Reality Controller Data Provider Settings", EditorStyles.boldLabel);
EditorGUILayout.HelpBox("This profile aids in configuring additional platform settings for the registered controller data provider. This can be anything from additional gestures or platform specific settings.", MessageType.Info);
base.OnInspectorGUI();

serializedObject.Update();
EditorGUILayout.Space();
EditorGUILayout.LabelField("Windows Gesture Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(windowsGestureAutoStart);
EditorGUILayout.PropertyField(manipulationGestures);
EditorGUILayout.PropertyField(navigationGestures);
EditorGUILayout.PropertyField(useRailsNavigation);
EditorGUILayout.PropertyField(railsNavigationGestures);
showGestureSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showGestureSettings, gestureSettingsFoldoutHeader, true);
if (showGestureSettings)
{
EditorGUILayout.PropertyField(windowsGestureAutoStart);
EditorGUILayout.PropertyField(manipulationGestures);
EditorGUILayout.PropertyField(navigationGestures);
EditorGUILayout.PropertyField(useRailsNavigation);
EditorGUILayout.PropertyField(railsNavigationGestures);
}

serializedObject.ApplyModifiedProperties();
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 481fc30

Please sign in to comment.