Skip to content

Commit fa46bd9

Browse files
More testing / patching
Refactored the InputAxis mapping Updated Base implementation, using Generic as a base for other OpenVR controllers
1 parent 2f1424a commit fa46bd9

File tree

10 files changed

+468
-78
lines changed

10 files changed

+468
-78
lines changed

Assets/MixedRealityToolkit/_Core/Definitions/Devices/DeviceInputType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ public enum DeviceInputType
6565
MiddleFinger,
6666
RingFinger,
6767
PinkyFinger,
68+
SecondaryButton,
6869
}
6970
}

Assets/MixedRealityToolkit/_Core/Devices/BaseController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ protected BaseController(TrackingState trackingState, Handedness controllerHande
3333
IsPositionAvailable = false;
3434
IsPositionApproximate = false;
3535
IsRotationAvailable = false;
36+
37+
Enabled = true;
3638
}
3739

40+
public bool Enabled { get; set; }
41+
3842
/// <summary>
3943
/// Returns the current Input System if enabled, otherwise null.
4044
/// </summary>
@@ -91,7 +95,7 @@ public void SetupConfiguration(Type controllerType)
9195
}
9296

9397
//If no controller mappings found, warn the user. Does not stop the project from running.
94-
if (Interactions == null || Interactions.Length < 1) { Debug.LogWarning($"No Controller mapping found for {controllerType}"); }
98+
if (Interactions == null || Interactions.Length < 1) { Debug.LogWarning($"No Controller mapping found for {controllerType}"); Enabled = false; }
9599
}
96100
}
97101

Assets/MixedRealityToolkit/_Core/Devices/OpenVR/GenericOpenVRController.cs

Lines changed: 69 additions & 60 deletions
Large diffs are not rendered by default.

Assets/MixedRealityToolkit/_Core/Devices/OpenVR/HTCViveController.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,60 @@
44
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Devices;
55
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
66
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
7+
using Microsoft.MixedReality.Toolkit.Internal.Utilities;
78

89
namespace Microsoft.MixedReality.Toolkit.Internal.Devices.OpenVR
910
{
1011
// TODO - Implement
11-
public class HTCViveController : BaseController
12+
public class HTCViveController : GenericOpenVRController
1213
{
1314
public HTCViveController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
1415
: base(trackingState, controllerHandedness, inputSource, interactions) { }
16+
17+
#region Base override configuration
18+
19+
private InputMappingAxisUtility.InputManagerAxis[] HTCViveControllerAxisMappings;
20+
21+
public override InputMappingAxisUtility.InputManagerAxis[] ControllerAxisMappings => HTCViveControllerAxisMappings;
22+
23+
/// <summary>
24+
/// Collection of input mapping constants, grouped in a single class for easier referencing.
25+
/// </summary>
26+
/// <remarks>
27+
/// Uses a fixed index array for controller input in the base / Generic class, as indicated in the array comments</remarks>
28+
private string[] HTCViveInputMappings =
29+
{
30+
"VIVE_TOUCHPAD_LEFT_CONTROLLER_HORIZONTAL", // 0 - TOUCHPAD_LEFT_CONTROLLER_HORIZONTAL
31+
"VIVE_TOUCHPAD_LEFT_CONTROLLER_VERTICAL", // 1 - TOUCHPAD_LEFT_CONTROLLER_VERTICAL
32+
"VIVE_TOUCHPAD_RIGHT_CONTROLLER_HORIZONTAL", // 2 - TOUCHPAD_RIGHT_CONTROLLER_HORIZONTAL
33+
"VIVE_TOUCHPAD_RIGHT_CONTROLLER_VERTICAL", // 3 - TOUCHPAD_RIGHT_CONTROLLER_VERTICAL
34+
"VIVE_TOUCHPAD_LEFT_CONTROLLER_HORIZONTAL", // 4 - THUMBSTICK_LEFT_CONTROLLER_HORIZONTAL
35+
"VIVE_TOUCHPAD_LEFT_CONTROLLER_VERTICAL", // 5 - THUMBSTICK_LEFT_CONTROLLER_VERTICAL
36+
"VIVE_TOUCHPAD_RIGHT_CONTROLLER_HORIZONTAL", // 6 - THUMBSTICK_RIGHT_CONTROLLER_HORIZONTAL
37+
"VIVE_TOUCHPAD_RIGHT_CONTROLLER_VERTICAL", // 7 - THUMBSTICK_RIGHT_CONTROLLER_VERTICAL
38+
"VIVE_TRIGGER_LEFT_CONTROLLER", // 8 - TRIGGER_LEFT_CONTROLLER
39+
"VIVE_TRIGGER_RIGHT_CONTROLLER", // 9 - TRIGGER_RIGHT_CONTROLLER
40+
"VIVE_GRIP_LEFT_CONTROLLER", // 10 - GRIP_LEFT_CONTROLLER
41+
"VIVE_GRIP_RIGHT_CONTROLLER" // 11 - GRIP_RIGHT_CONTROLLER
42+
};
43+
44+
public override string[] VRInputMappings => HTCViveInputMappings;
45+
46+
public override void Initialise()
47+
{
48+
HTCViveControllerAxisMappings = new InputMappingAxisUtility.InputManagerAxis[]
49+
{
50+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[0], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 1 },
51+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[1], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 2 },
52+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[2], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 4 },
53+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[3], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 5 },
54+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[8], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 9 },
55+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[9], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 10 },
56+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[10], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 11 },
57+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[11], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 12 }
58+
};
59+
}
60+
61+
#endregion Base override configuration
1562
}
1663
}

Assets/MixedRealityToolkit/_Core/Devices/OpenVR/OculusTouchController.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,61 @@
44
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Devices;
55
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
66
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
7+
using Microsoft.MixedReality.Toolkit.Internal.Utilities;
78

89
namespace Microsoft.MixedReality.Toolkit.Internal.Devices.OpenVR
910
{
1011
// TODO - Implement
11-
public class OculusTouchController : BaseController
12+
public class OculusTouchController : GenericOpenVRController
1213
{
1314
public OculusTouchController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource, MixedRealityInteractionMapping[] interactions)
1415
: base(trackingState, controllerHandedness, inputSource, interactions) { }
16+
17+
#region Base override configuration
18+
19+
private InputMappingAxisUtility.InputManagerAxis[] OcculusTouchControllerAxisMappings;
20+
21+
public override InputMappingAxisUtility.InputManagerAxis[] ControllerAxisMappings => OcculusTouchControllerAxisMappings;
22+
23+
/// <summary>
24+
/// Collection of input mapping constants, grouped in a single class for easier referencing.
25+
/// </summary>
26+
/// <remarks>
27+
/// Uses a fixed index array for controller input in the base / Generic class, as indicated in the array comments</remarks>
28+
private string[] OcculusTouchInputMappings =
29+
{
30+
"OTOUCH_TOUCHPAD_LEFT_CONTROLLER_HORIZONTAL", // 0 - TOUCHPAD_LEFT_CONTROLLER_HORIZONTAL
31+
"OTOUCH_TOUCHPAD_LEFT_CONTROLLER_VERTICAL", // 1 - TOUCHPAD_LEFT_CONTROLLER_VERTICAL
32+
"OTOUCH_TOUCHPAD_RIGHT_CONTROLLER_HORIZONTAL", // 2 - TOUCHPAD_RIGHT_CONTROLLER_HORIZONTAL
33+
"OTOUCH_TOUCHPAD_RIGHT_CONTROLLER_VERTICAL", // 3 - TOUCHPAD_RIGHT_CONTROLLER_VERTICAL
34+
"OTOUCH_TOUCHPAD_LEFT_CONTROLLER_HORIZONTAL", // 4 - THUMBSTICK_LEFT_CONTROLLER_HORIZONTAL
35+
"OTOUCH_TOUCHPAD_LEFT_CONTROLLER_VERTICAL", // 5 - THUMBSTICK_LEFT_CONTROLLER_VERTICAL
36+
"OTOUCH_TOUCHPAD_RIGHT_CONTROLLER_HORIZONTAL", // 6 - THUMBSTICK_RIGHT_CONTROLLER_HORIZONTAL
37+
"OTOUCH_TOUCHPAD_RIGHT_CONTROLLER_VERTICAL", // 7 - THUMBSTICK_RIGHT_CONTROLLER_VERTICAL
38+
"OTOUCH_TRIGGER_LEFT_CONTROLLER", // 8 - TRIGGER_LEFT_CONTROLLER
39+
"OTOUCH_TRIGGER_RIGHT_CONTROLLER", // 9 - TRIGGER_RIGHT_CONTROLLER
40+
"OTOUCH_GRIP_LEFT_CONTROLLER", // 10 - GRIP_LEFT_CONTROLLER
41+
"OTOUCH_GRIP_RIGHT_CONTROLLER" // 11 - GRIP_RIGHT_CONTROLLER
42+
};
43+
44+
public override string[] VRInputMappings => OcculusTouchInputMappings;
45+
46+
public override void Initialise()
47+
{
48+
OcculusTouchControllerAxisMappings = new InputMappingAxisUtility.InputManagerAxis[]
49+
{
50+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[0], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 1 },
51+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[1], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 2 },
52+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[2], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 4 },
53+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[3], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 5 },
54+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[8], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 9 },
55+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[9], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 10 },
56+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[10], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 11 },
57+
new InputMappingAxisUtility.InputManagerAxis() { Name = VRInputMappings[11], Dead = 0.001f, Sensitivity = 1, Invert = false, Type = InputMappingAxisUtility.MappingAxisType.JoystickAxis, Axis = 12 }
58+
};
59+
}
60+
61+
#endregion Base override configuration
62+
1563
}
1664
}

Assets/MixedRealityToolkit/_Core/Devices/OpenVR/OpenVRDeviceManager.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public override void Update()
4848
{
4949
if (IsNodeTypeSupported(nodeStates[i]) && activeControllers.ContainsKey(nodeStates[i].nodeType))
5050
{
51+
//TODO - Need logic to determine controller type (if possible)
5152
controller = activeControllers[nodeStates[i].nodeType] as GenericOpenVRController;
52-
controller.UpdateController(nodeStates[i]);
53-
//Debug.Log($"Updating node for [{nodeStates[i].nodeType}], name [{InputTracking.GetNodeName(nodeStates[i].uniqueID)}]");
53+
if(controller.Enabled) controller.UpdateController(nodeStates[i]);
5454
}
5555
}
5656
}
@@ -120,12 +120,13 @@ private bool IsNodeTypeSupported(XRNodeState obj)
120120
/// </summary>
121121
/// <param name="interactionSourceState">Source State provided by the SDK</param>
122122
/// <returns>New or Existing Controller Input Source</returns>
123-
private GenericOpenVRController GetOrAddController(XRNodeState xrNodeState)
123+
private IMixedRealityController GetOrAddController(XRNodeState xrNodeState)
124124
{
125125
//If a device is already registered with the ID provided, just return it.
126126
if (activeControllers.ContainsKey(xrNodeState.nodeType))
127127
{
128-
var controller = activeControllers[xrNodeState.nodeType] as GenericOpenVRController;
128+
//TODO - Need logic to determine controller type (if possible)
129+
var controller = activeControllers[xrNodeState.nodeType];
129130
Debug.Assert(controller != null);
130131
return controller;
131132
}
@@ -146,8 +147,11 @@ private GenericOpenVRController GetOrAddController(XRNodeState xrNodeState)
146147
}
147148

148149
var inputSource = InputSystem?.RequestNewGenericInputSource($"Generic OpenVR Controller {controllingHand}");
150+
151+
//TODO - Need logic to determine controller type (if possible)
149152
var detectedController = new GenericOpenVRController(TrackingState.NotTracked, controllingHand, inputSource);
150153
detectedController.SetupConfiguration(typeof(GenericOpenVRController));
154+
151155
activeControllers.Add(xrNodeState.nodeType, detectedController);
152156

153157
return detectedController;

0 commit comments

Comments
 (0)