diff --git a/Editor/Data/EditorWindowOptions.json b/Editor/Data/EditorWindowOptions.json index e699e1abd..8705d9290 100644 --- a/Editor/Data/EditorWindowOptions.json +++ b/Editor/Data/EditorWindowOptions.json @@ -563,6 +563,10 @@ { "x": -24.0, "y": 220.0 + }, + { + "x": -20.0, + "y": 321.0 } ], "IsLabelFlipped": [ @@ -584,6 +588,7 @@ false, true, true, + true, true ] }, @@ -662,6 +667,10 @@ { "x": 440.0, "y": 220.0 + }, + { + "x": 440.0, + "y": 323.0 } ], "IsLabelFlipped": [ @@ -682,6 +691,7 @@ true, false, false, + false, false ] }, @@ -756,6 +766,10 @@ { "x": 440.0, "y": 220.0 + }, + { + "x": 440.0, + "y": 322.0 } ], "IsLabelFlipped": [ @@ -775,6 +789,7 @@ false, true, false, + false, false ] }, @@ -853,6 +868,10 @@ { "x": -68.0, "y": 220.0 + }, + { + "x": -20.0, + "y": 322.0 } ], "IsLabelFlipped": [ @@ -873,6 +892,7 @@ false, true, true, + true, true ] }, diff --git a/Runtime/Providers/Controllers/BaseController.cs b/Runtime/Providers/Controllers/BaseController.cs index 38bdb3a58..f788b2f66 100644 --- a/Runtime/Providers/Controllers/BaseController.cs +++ b/Runtime/Providers/Controllers/BaseController.cs @@ -99,6 +99,12 @@ protected BaseController(IMixedRealityControllerDataProvider controllerDataProvi /// public virtual MixedRealityInteractionMapping[] DefaultRightHandedInteractions { get; } = new MixedRealityInteractionMapping[0]; + /// + /// Local offset from the controller position defining where the grip pose is. + /// The grip pose may be used to attach things to the controller when grabbing objects. + /// + protected virtual MixedRealityPose GripPoseOffset => MixedRealityPose.ZeroIdentity; + #region IMixedRealityController Implementation /// diff --git a/Runtime/Providers/Controllers/OpenVR/GenericOpenVRController.cs b/Runtime/Providers/Controllers/OpenVR/GenericOpenVRController.cs index de57d5cdb..e0f4bbd12 100644 --- a/Runtime/Providers/Controllers/OpenVR/GenericOpenVRController.cs +++ b/Runtime/Providers/Controllers/OpenVR/GenericOpenVRController.cs @@ -201,12 +201,12 @@ protected void UpdateControllerData(XRNodeState state) IsRotationAvailable = state.TryGetRotation(out CurrentControllerRotation); // Devices are considered tracked if we receive position OR rotation data from the sensors. - TrackingState = (IsPositionAvailable || IsRotationAvailable) ? Definitions.Devices.TrackingState.Tracked : Definitions.Devices.TrackingState.NotTracked; + TrackingState = (IsPositionAvailable || IsRotationAvailable) ? TrackingState.Tracked : TrackingState.NotTracked; } else { // The input source does not support tracking. - TrackingState = Definitions.Devices.TrackingState.NotApplicable; + TrackingState = TrackingState.NotApplicable; } CurrentControllerPose.Position = CurrentControllerPosition; @@ -218,7 +218,7 @@ protected void UpdateControllerData(XRNodeState state) MixedRealityToolkit.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState); } - if (TrackingState == Definitions.Devices.TrackingState.Tracked && LastControllerPose != CurrentControllerPose) + if (TrackingState == TrackingState.Tracked && LastControllerPose != CurrentControllerPose) { if (IsPositionAvailable && IsRotationAvailable) { diff --git a/Runtime/Providers/Controllers/OpenVR/OculusTouchOpenVRController.cs b/Runtime/Providers/Controllers/OpenVR/OculusTouchOpenVRController.cs index d180cb56c..ae1abb56f 100644 --- a/Runtime/Providers/Controllers/OpenVR/OculusTouchOpenVRController.cs +++ b/Runtime/Providers/Controllers/OpenVR/OculusTouchOpenVRController.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using UnityEngine; +using XRTK.Extensions; using XRTK.Definitions.Controllers; using XRTK.Definitions.Devices; using XRTK.Definitions.Utilities; @@ -17,9 +18,7 @@ public class OculusTouchOpenVRController : GenericOpenVRController /// public OculusTouchOpenVRController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile) - : base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile) - { - } + : base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile) { } /// public override MixedRealityInteractionMapping[] DefaultLeftHandedInteractions => new[] @@ -41,7 +40,8 @@ public OculusTouchOpenVRController(IMixedRealityControllerDataProvider controlle new MixedRealityInteractionMapping("Button.Three Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton12), new MixedRealityInteractionMapping("Button.Four Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton13), new MixedRealityInteractionMapping("Touch.PrimaryThumbRest Touch", AxisType.Digital, DeviceInputType.ThumbTouch, KeyCode.JoystickButton18), - new MixedRealityInteractionMapping("Touch.PrimaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_17) + new MixedRealityInteractionMapping("Touch.PrimaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_17), + new MixedRealityInteractionMapping("Grip Pose", AxisType.SixDof, DeviceInputType.SpatialGrip) }; /// @@ -63,7 +63,36 @@ public OculusTouchOpenVRController(IMixedRealityControllerDataProvider controlle new MixedRealityInteractionMapping("Button.One Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton10), new MixedRealityInteractionMapping("Button.Two Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton11), new MixedRealityInteractionMapping("Touch.SecondaryThumbRest Touch", AxisType.Digital, DeviceInputType.ThumbTouch, KeyCode.JoystickButton19), - new MixedRealityInteractionMapping("Touch.SecondaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_18) + new MixedRealityInteractionMapping("Touch.SecondaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_18), + new MixedRealityInteractionMapping("Grip Pose", AxisType.SixDof, DeviceInputType.SpatialGrip) }; + + public override void UpdateController() + { + base.UpdateController(); + + if (TrackingState == TrackingState.Tracked) + { + for (int i = 0; i < Interactions?.Length; i++) + { + var interactionMapping = Interactions[i]; + switch (interactionMapping.InputType) + { + case DeviceInputType.SpatialGrip: + UpdateSpatialGripData(interactionMapping); + interactionMapping.RaiseInputAction(InputSource, ControllerHandedness); + break; + } + } + } + } + + private void UpdateSpatialGripData(MixedRealityInteractionMapping interactionMapping) + { + Debug.Assert(interactionMapping.AxisType == AxisType.SixDof); + interactionMapping.PoseData = new MixedRealityPose( + CurrentControllerPose.Position + GripPoseOffset.Position, + Quaternion.Euler(CurrentControllerPose.Rotation.eulerAngles + GripPoseOffset.Rotation.eulerAngles)); + } } } \ No newline at end of file