From 80912a4004b8de80570c5c8adb17e16021bb68fc Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Fri, 11 Oct 2024 14:59:37 +0100 Subject: [PATCH 1/2] Fix the logic for handling handedness --- .../Logitech/Scripts/VrStylusHandler.cs | 62 ++++++++++++++----- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/Assets/ThirdParty/Logitech/Scripts/VrStylusHandler.cs b/Assets/ThirdParty/Logitech/Scripts/VrStylusHandler.cs index 97e5d7ef55..0e2a73117d 100644 --- a/Assets/ThirdParty/Logitech/Scripts/VrStylusHandler.cs +++ b/Assets/ThirdParty/Logitech/Scripts/VrStylusHandler.cs @@ -67,6 +67,8 @@ public override bool CanDraw() private float _hapticClickAmplitude = 0.9f; private float _hapticClickMinThreshold = 0.2f; + private OVRPlugin.Hand prevHandSetting = OVRPlugin.Hand.None; + private void UpdatePose() { _positionIsTracked = false; @@ -80,22 +82,54 @@ private void UpdatePose() // The MX Ink interaction profile is: /interaction_profiles/logitech/mx_ink_stylus_logitech // Find whether the Logitech MX Ink is on the left or the right hand - bool stylusIsOnLeftHand = leftDevice.Contains("logitech"); - bool stylusIsOnRightHand = rightDevice.Contains("logitech"); - // Debug.Log($"Device: Left hand: {leftDevice}, Right hand: {rightDevice}"); + bool stylusIsAssignedLeft = leftDevice.Contains("logitech"); + bool stylusIsAssignedRight = rightDevice.Contains("logitech"); + // Flag the stylus as active/inactive, on right/left hand - _stylus.isActive = stylusIsOnLeftHand || stylusIsOnRightHand; - _stylus.isOnRightHand = stylusIsOnRightHand; - // Hide the 3D model if not active - _mxInk_model.SetActive(_stylus.isActive); - // Hacky - InputManager.m_Instance.ShowController(!_stylus.isActive, stylusIsOnLeftHand ? 0 : 1); - InputManager.m_Instance.ShowController(true, stylusIsOnLeftHand ? 1 : 0); + _stylus.isActive = stylusIsAssignedLeft || stylusIsAssignedRight; + _stylus.isOnRightHand = stylusIsAssignedRight; + + if (!_stylus.isActive) + { + _mxInk_model.SetActive(false); + InputManager.m_Instance.ShowController(true, 0); + InputManager.m_Instance.ShowController(true, 1); + return; + } + + _mxInk_model.SetActive(true); + + // Initial pass. Set our handedness based on the OS settings + if (prevHandSetting == OVRPlugin.Hand.None) + { + prevHandSetting = stylusIsAssignedRight ? OVRPlugin.Hand.HandRight : OVRPlugin.Hand.HandLeft; + // If both stylus and wand are assigned to the same hand, swap the controls + if (stylusIsAssignedRight == InputManager.m_Instance.WandOnRight) + { + SketchControlsScript.DoSwapControls(); + } + } + else + { + // Subsequent passes. Check if the handedness has changed + var newHandSetting = stylusIsAssignedRight ? OVRPlugin.Hand.HandRight : OVRPlugin.Hand.HandLeft; + if (newHandSetting != prevHandSetting) + { + // If both stylus and wand are assigned to the same hand, swap the controls + if (stylusIsAssignedRight == InputManager.m_Instance.WandOnRight) + { + SketchControlsScript.DoSwapControls(); + } + prevHandSetting = newHandSetting; + } + } - // Select the right/left hand stylus pose to be used - string MX_Ink_Pose = _stylus.isOnRightHand ? MX_Ink_Pose_Right : MX_Ink_Pose_Left; + // Not sure why but this works whether stylusIsAssignedRight or stylusIsAssignedLeft + InputManager.Brush.ShowController(false); + InputManager.Wand.ShowController(true); - if (OVRPlugin.GetActionStatePose(MX_Ink_Pose, out OVRPlugin.Posef handPose)) + string mxInkPose = stylusIsAssignedRight ? MX_Ink_Pose_Right : MX_Ink_Pose_Left; + if (OVRPlugin.GetActionStatePose(mxInkPose, out OVRPlugin.Posef handPose)) { transform.localPosition = handPose.Position.FromFlippedZVector3f(); transform.rotation = handPose.Orientation.FromFlippedZQuatf(); @@ -106,7 +140,7 @@ private void UpdatePose() } else { - Debug.LogError($"MX_Ink: Error getting Pose action name {MX_Ink_Pose}, check logcat for specifics."); + Debug.LogError($"MX_Ink: Error getting Pose action name {mxInkPose}, check logcat for specifics."); } } From bb7cf00cf173cf0ce8589e03a2662cf72a27e1d4 Mon Sep 17 00:00:00 2001 From: Mario Gutierrez Date: Tue, 15 Oct 2024 17:36:52 +0100 Subject: [PATCH 2/2] No need to check isBrush flag: if stylus is active, it is brush --- Assets/Scripts/Input/UnityXRControllerInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Input/UnityXRControllerInfo.cs b/Assets/Scripts/Input/UnityXRControllerInfo.cs index 3d7707137b..cf114bf029 100644 --- a/Assets/Scripts/Input/UnityXRControllerInfo.cs +++ b/Assets/Scripts/Input/UnityXRControllerInfo.cs @@ -133,7 +133,7 @@ public override void Update() private bool IsStylusActive() { - return stylusState.isActive && isBrush; + return stylusState.isActive; } public override Vector2 GetPadValueDelta()