Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

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

* updated oculus controller

* updated references

* updated profile constructor parameter reference to enable inspector

* updated references

* Added default controller definitions

* updated hand provider inspector

* fixed hand inspector

* cleaned up references

* cleaned up controller interaction mappings a bit

* updated references

fixed GetCOntroller return types

* updated controller instance creation

* added default constructor

* updated TryRenderController method

* removed asset menu

* Remove obsolete SetupDefaultInteractions (#53)

* updated references to camera system

* Changed timing of initialization to prevent race condition

* updated hands inspector

* updated constructors for data providers

* Change requests for controller provider inspectors (#55)

* Update indent levels for oculus settings

* Cache GUIContent

* Removed head height settings in controllers

* added initial platform definition for Oculus

* removed

* Added Oculus Camera Data Providers

* updated icons

* Updated platform check for Version and check headset connected for runtime. (#59)

Tested on platform

* Added platform overrides

Co-authored-by: Dino Fejzagic <[email protected]>
Co-authored-by: Simon (Darkside) Jackson <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2020
1 parent bb259f0 commit b5478d9
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

using System;
using UnityEngine;
using XRTK.Definitions.Controllers;
using XRTK.Definitions.Devices;
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.Utilities;
using XRTK.Extensions;
using XRTK.Interfaces.InputSystem;
using XRTK.Interfaces.Providers.Controllers;
using XRTK.Oculus.Extensions;
using XRTK.Providers.Controllers;
using XRTK.Services;

namespace XRTK.Oculus.Controllers
{
public class BaseOculusController : BaseController
public abstract class BaseOculusController : BaseController
{
public BaseOculusController() : base() { }

/// <inheritdoc />
public BaseOculusController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, OculusApi.Controller controllerType, OculusApi.Node nodeType, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(controllerDataProvider, trackingState, controllerHandedness, inputSource, interactions)
protected BaseOculusController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile, OculusApi.Controller controllerType = OculusApi.Controller.None, OculusApi.Node nodeType = OculusApi.Node.None)
: base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile)
{
ControllerType = controllerType;
NodeType = nodeType;
Expand All @@ -28,51 +29,51 @@ public BaseOculusController(IMixedRealityControllerDataProvider controllerDataPr
/// <summary>
/// The Oculus Node Type.
/// </summary>
public OculusApi.Node NodeType { get; }
private OculusApi.Node NodeType { get; }

/// <summary>
/// The Oculus Controller Type.
/// </summary>
public OculusApi.Controller ControllerType { get; }
private OculusApi.Controller ControllerType { get; }

private OculusApi.ControllerState4 previousState = new OculusApi.ControllerState4();
private OculusApi.ControllerState4 currentState = new OculusApi.ControllerState4();

/// <inheritdoc />
public override MixedRealityInteractionMapping[] DefaultInteractions => new[]
{
new MixedRealityInteractionMapping(0, "Button.A Press", AxisType.Digital, "A", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(1, "Button.B Press", AxisType.Digital, "B", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(2, "Button.X Press", AxisType.Digital, "X", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(3, "Button.Y Press", AxisType.Digital, "Y", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(4, "Button.Start Press", AxisType.Digital, "Start", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(5, "Button.Back Press", AxisType.Digital, "Back", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(6, "Button.LShoulder Press", AxisType.Digital, "LShoulder", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(7, "Axis1D.LIndexTrigger", AxisType.SingleAxis, "LIndexTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping(8, "Axis1D.LIndexTrigger Touch", AxisType.Digital, "LIndexTrigger", DeviceInputType.TriggerTouch),
new MixedRealityInteractionMapping(9, "Axis1D.LIndexTrigger Near Touch", AxisType.Digital, "LIndexTrigger", DeviceInputType.TriggerNearTouch),
new MixedRealityInteractionMapping(10, "Axis1D.LIndexTrigger Press", AxisType.Digital, "LIndexTrigger", DeviceInputType.TriggerPress),
new MixedRealityInteractionMapping(11, "Axis1D.LHandTrigger Press", AxisType.SingleAxis, "LHandTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping(12, "Axis2D.LThumbstick", AxisType.DualAxis, "PrimaryThumbstick", DeviceInputType.ThumbStick),
new MixedRealityInteractionMapping(13, "Button.LThumbstick Touch", AxisType.Digital, "LThumbstick", DeviceInputType.ThumbStickTouch),
new MixedRealityInteractionMapping(14, "Button.LThumbstick Near Touch", AxisType.Digital, "LThumbstick", DeviceInputType.ThumbNearTouch),
new MixedRealityInteractionMapping(15, "Button.LThumbstick Press", AxisType.Digital, "LThumbstick", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping(16, "Button.RShoulder Press", AxisType.Digital, "RShoulder", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping(17, "Axis1D.RIndexTrigger", AxisType.SingleAxis, "RIndexTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping(18, "Axis1D.RIndexTrigger Touch", AxisType.Digital, "RIndexTrigger", DeviceInputType.TriggerTouch),
new MixedRealityInteractionMapping(19, "Axis1D.RIndexTrigger Near Touch", AxisType.Digital, "RIndexTrigger", DeviceInputType.TriggerNearTouch),
new MixedRealityInteractionMapping(20, "Axis1D.RIndexTrigger Press", AxisType.Digital, "RIndexTrigger", DeviceInputType.TriggerPress),
new MixedRealityInteractionMapping(21, "Axis1D.RHandTrigger Press", AxisType.SingleAxis, "RHandTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping(22, "Axis2D.RThumbstick", AxisType.DualAxis, "SecondaryThumbstick", DeviceInputType.ThumbStick),
new MixedRealityInteractionMapping(23, "Button.RThumbstick Touch", AxisType.Digital, "RThumbstick", DeviceInputType.ThumbStickTouch),
new MixedRealityInteractionMapping(24, "Button.RThumbstick Near Touch", AxisType.Digital, "RThumbstick", DeviceInputType.ThumbNearTouch),
new MixedRealityInteractionMapping(25, "Button.RThumbstick Press", AxisType.Digital, "RThumbstick", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping(26, "Axis2D.Dpad", AxisType.DualAxis, DeviceInputType.ThumbStick, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(27, "Button.DpadUp Press", AxisType.Digital, "DpadUp", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping(28, "Button.DpadDown Press", AxisType.Digital, "DpadDown", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping(29, "Button.DpadLeft Press", AxisType.Digital, "DpadLeft", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping(30, "Button.DpadRight Press", AxisType.Digital, "DpadRight", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping(31, "Button.RTouchpad", AxisType.Digital, "RTouchpad", DeviceInputType.ThumbTouch),
new MixedRealityInteractionMapping("Button.A Press", AxisType.Digital, "A", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Button.B Press", AxisType.Digital, "B", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Button.X Press", AxisType.Digital, "X", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Button.Y Press", AxisType.Digital, "Y", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Button.Start Press", AxisType.Digital, "Start", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Button.Back Press", AxisType.Digital, "Back", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Button.LShoulder Press", AxisType.Digital, "LShoulder", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Axis1D.LIndexTrigger", AxisType.SingleAxis, "LIndexTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping("Axis1D.LIndexTrigger Touch", AxisType.Digital, "LIndexTrigger", DeviceInputType.TriggerTouch),
new MixedRealityInteractionMapping("Axis1D.LIndexTrigger Near Touch", AxisType.Digital, "LIndexTrigger", DeviceInputType.TriggerNearTouch),
new MixedRealityInteractionMapping("Axis1D.LIndexTrigger Press", AxisType.Digital, "LIndexTrigger", DeviceInputType.TriggerPress),
new MixedRealityInteractionMapping("Axis1D.LHandTrigger Press", AxisType.SingleAxis, "LHandTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping("Axis2D.LThumbstick", AxisType.DualAxis, "PrimaryThumbstick", DeviceInputType.ThumbStick),
new MixedRealityInteractionMapping("Button.LThumbstick Touch", AxisType.Digital, "LThumbstick", DeviceInputType.ThumbStickTouch),
new MixedRealityInteractionMapping("Button.LThumbstick Near Touch", AxisType.Digital, "LThumbstick", DeviceInputType.ThumbNearTouch),
new MixedRealityInteractionMapping("Button.LThumbstick Press", AxisType.Digital, "LThumbstick", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping("Button.RShoulder Press", AxisType.Digital, "RShoulder", DeviceInputType.ButtonPress),
new MixedRealityInteractionMapping("Axis1D.RIndexTrigger", AxisType.SingleAxis, "RIndexTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping("Axis1D.RIndexTrigger Touch", AxisType.Digital, "RIndexTrigger", DeviceInputType.TriggerTouch),
new MixedRealityInteractionMapping("Axis1D.RIndexTrigger Near Touch", AxisType.Digital, "RIndexTrigger", DeviceInputType.TriggerNearTouch),
new MixedRealityInteractionMapping("Axis1D.RIndexTrigger Press", AxisType.Digital, "RIndexTrigger", DeviceInputType.TriggerPress),
new MixedRealityInteractionMapping("Axis1D.RHandTrigger Press", AxisType.SingleAxis, "RHandTrigger", DeviceInputType.Trigger),
new MixedRealityInteractionMapping("Axis2D.RThumbstick", AxisType.DualAxis, "SecondaryThumbstick", DeviceInputType.ThumbStick),
new MixedRealityInteractionMapping("Button.RThumbstick Touch", AxisType.Digital, "RThumbstick", DeviceInputType.ThumbStickTouch),
new MixedRealityInteractionMapping("Button.RThumbstick Near Touch", AxisType.Digital, "RThumbstick", DeviceInputType.ThumbNearTouch),
new MixedRealityInteractionMapping("Button.RThumbstick Press", AxisType.Digital, "RThumbstick", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping("Axis2D.Dpad", AxisType.DualAxis, DeviceInputType.ThumbStick),
new MixedRealityInteractionMapping("Button.DpadUp Press", AxisType.Digital, "DpadUp", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping("Button.DpadDown Press", AxisType.Digital, "DpadDown", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping("Button.DpadLeft Press", AxisType.Digital, "DpadLeft", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping("Button.DpadRight Press", AxisType.Digital, "DpadRight", DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping("Button.RTouchpad", AxisType.Digital, "RTouchpad", DeviceInputType.ThumbTouch),
};

/// <inheritdoc />
Expand All @@ -81,12 +82,6 @@ public BaseOculusController(IMixedRealityControllerDataProvider controllerDataPr
/// <inheritdoc />
public override MixedRealityInteractionMapping[] DefaultRightHandedInteractions => DefaultInteractions;

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

private MixedRealityPose currentPointerPose = MixedRealityPose.ZeroIdentity;
private MixedRealityPose lastControllerPose = MixedRealityPose.ZeroIdentity;
private MixedRealityPose currentControllerPose = MixedRealityPose.ZeroIdentity;
Expand Down
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 System;
using System.Collections.Generic;
using UnityEngine;
using XRTK.Definitions.Controllers;
using XRTK.Definitions.Devices;
using XRTK.Interfaces.InputSystem;
using XRTK.Oculus.Extensions;
using XRTK.Oculus.Profiles;
using XRTK.Providers.Controllers;
using XRTK.Services;

Expand All @@ -15,12 +16,12 @@ namespace XRTK.Oculus.Controllers
public class OculusControllerDataProvider : BaseControllerDataProvider
{
/// <inheritdoc />
public OculusControllerDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile, IMixedRealityInputSystem parentService)
public OculusControllerDataProvider(string name, uint priority, OculusControllerDataProviderProfile profile, IMixedRealityInputSystem parentService)
: base(name, priority, profile, parentService)
{
}

private const float DeviceRefreshInterval = 3.0f;
private const float DEVICE_REFRESH_INTERVAL = 3.0f;

/// <summary>
/// Dictionary to capture all active controllers detected
Expand All @@ -41,7 +42,7 @@ public override void Update()

deviceRefreshTimer += Time.unscaledDeltaTime;

if (deviceRefreshTimer >= DeviceRefreshInterval)
if (deviceRefreshTimer >= DEVICE_REFRESH_INTERVAL)
{
deviceRefreshTimer = 0.0f;
RefreshDevices();
Expand Down Expand Up @@ -88,34 +89,30 @@ private BaseOculusController GetOrAddController(OculusApi.Controller controllerM

if (!addController) { return null; }

var controllerType = controllerMask.ToControllerType().ToImplementation();
if (controllerType == null)
{
// If we could not map the controller to a type supported by this
// XRTK platform it's ignored. This is intended behaviour.
return null;
}
var controllerType = GetCurrentControllerType(controllerMask);

var controllingHand = controllerMask.ToHandedness();
var nodeType = controllingHand.ToNode();
var handedness = controllerMask.ToHandedness();
var nodeType = handedness.ToNode();

var pointers = RequestPointers(typeof(BaseOculusController), controllingHand);
var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"Oculus Controller {controllingHand}", pointers);
var detectedController = new BaseOculusController(this, TrackingState.NotTracked, controllingHand, controllerMask, nodeType, inputSource);
BaseOculusController detectedController;

if (!detectedController.SetupConfiguration(controllerType))
try
{
// Controller failed to be setup correctly.
// Return null so we don't raise the source detected.
detectedController = Activator.CreateInstance(controllerType, this, TrackingState.NotTracked, handedness, GetControllerMappingProfile(controllerType, handedness), controllerMask, nodeType) as BaseOculusController;
}
catch (Exception e)
{
Debug.LogError($"Failed to create {controllerType.Name} controller!\n{e}");
return null;
}

for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++)
if (detectedController == null)
{
detectedController.InputSource.Pointers[i].Controller = detectedController;
Debug.LogError($"Failed to create {controllerType.Name} controller!");
return null;
}

detectedController.TryRenderControllerModel(controllerType);
detectedController.TryRenderControllerModel();

activeControllers.Add(controllerMask, detectedController);
AddController(detectedController);
Expand Down Expand Up @@ -217,5 +214,23 @@ private void RaiseSourceLost(OculusApi.Controller activeController, bool clearFr
activeControllers.Remove(activeController);
}
}

private static Type GetCurrentControllerType(OculusApi.Controller controllerMask)
{
switch (controllerMask)
{
case OculusApi.Controller.LTouch:
case OculusApi.Controller.RTouch:
case OculusApi.Controller.Touch:
return typeof(OculusTouchController);
case OculusApi.Controller.Remote:
return typeof(OculusRemoteController);
case OculusApi.Controller.LTrackedRemote:
case OculusApi.Controller.RTrackedRemote:
return typeof(OculusGoController);
default:
return null;
}
}
}
}
Loading

0 comments on commit b5478d9

Please sign in to comment.