@@ -67,6 +67,8 @@ public override bool CanDraw()
67
67
private float _hapticClickAmplitude = 0.9f ;
68
68
private float _hapticClickMinThreshold = 0.2f ;
69
69
70
+ private OVRPlugin . Hand prevHandSetting = OVRPlugin . Hand . None ;
71
+
70
72
private void UpdatePose ( )
71
73
{
72
74
_positionIsTracked = false ;
@@ -80,22 +82,54 @@ private void UpdatePose()
80
82
// The MX Ink interaction profile is: /interaction_profiles/logitech/mx_ink_stylus_logitech
81
83
82
84
// Find whether the Logitech MX Ink is on the left or the right hand
83
- bool stylusIsOnLeftHand = leftDevice . Contains ( "logitech" ) ;
84
- bool stylusIsOnRightHand = rightDevice . Contains ( "logitech" ) ;
85
- // Debug.Log($"Device: Left hand: {leftDevice}, Right hand: {rightDevice}");
85
+ bool stylusIsAssignedLeft = leftDevice . Contains ( "logitech" ) ;
86
+ bool stylusIsAssignedRight = rightDevice . Contains ( "logitech" ) ;
87
+
86
88
// Flag the stylus as active/inactive, on right/left hand
87
- _stylus . isActive = stylusIsOnLeftHand || stylusIsOnRightHand ;
88
- _stylus . isOnRightHand = stylusIsOnRightHand ;
89
- // Hide the 3D model if not active
90
- _mxInk_model . SetActive ( _stylus . isActive ) ;
91
- // Hacky
92
- InputManager . m_Instance . ShowController ( ! _stylus . isActive , stylusIsOnLeftHand ? 0 : 1 ) ;
93
- InputManager . m_Instance . ShowController ( true , stylusIsOnLeftHand ? 1 : 0 ) ;
89
+ _stylus . isActive = stylusIsAssignedLeft || stylusIsAssignedRight ;
90
+ _stylus . isOnRightHand = stylusIsAssignedRight ;
91
+
92
+ if ( ! _stylus . isActive )
93
+ {
94
+ _mxInk_model . SetActive ( false ) ;
95
+ InputManager . m_Instance . ShowController ( true , 0 ) ;
96
+ InputManager . m_Instance . ShowController ( true , 1 ) ;
97
+ return ;
98
+ }
99
+
100
+ _mxInk_model . SetActive ( true ) ;
101
+
102
+ // Initial pass. Set our handedness based on the OS settings
103
+ if ( prevHandSetting == OVRPlugin . Hand . None )
104
+ {
105
+ prevHandSetting = stylusIsAssignedRight ? OVRPlugin . Hand . HandRight : OVRPlugin . Hand . HandLeft ;
106
+ // If both stylus and wand are assigned to the same hand, swap the controls
107
+ if ( stylusIsAssignedRight == InputManager . m_Instance . WandOnRight )
108
+ {
109
+ SketchControlsScript . DoSwapControls ( ) ;
110
+ }
111
+ }
112
+ else
113
+ {
114
+ // Subsequent passes. Check if the handedness has changed
115
+ var newHandSetting = stylusIsAssignedRight ? OVRPlugin . Hand . HandRight : OVRPlugin . Hand . HandLeft ;
116
+ if ( newHandSetting != prevHandSetting )
117
+ {
118
+ // If both stylus and wand are assigned to the same hand, swap the controls
119
+ if ( stylusIsAssignedRight == InputManager . m_Instance . WandOnRight )
120
+ {
121
+ SketchControlsScript . DoSwapControls ( ) ;
122
+ }
123
+ prevHandSetting = newHandSetting ;
124
+ }
125
+ }
94
126
95
- // Select the right/left hand stylus pose to be used
96
- string MX_Ink_Pose = _stylus . isOnRightHand ? MX_Ink_Pose_Right : MX_Ink_Pose_Left ;
127
+ // Not sure why but this works whether stylusIsAssignedRight or stylusIsAssignedLeft
128
+ InputManager . Brush . ShowController ( false ) ;
129
+ InputManager . Wand . ShowController ( true ) ;
97
130
98
- if ( OVRPlugin . GetActionStatePose ( MX_Ink_Pose , out OVRPlugin . Posef handPose ) )
131
+ string mxInkPose = stylusIsAssignedRight ? MX_Ink_Pose_Right : MX_Ink_Pose_Left ;
132
+ if ( OVRPlugin . GetActionStatePose ( mxInkPose , out OVRPlugin . Posef handPose ) )
99
133
{
100
134
transform . localPosition = handPose . Position . FromFlippedZVector3f ( ) ;
101
135
transform . rotation = handPose . Orientation . FromFlippedZQuatf ( ) ;
@@ -106,7 +140,7 @@ private void UpdatePose()
106
140
}
107
141
else
108
142
{
109
- Debug . LogError ( $ "MX_Ink: Error getting Pose action name { MX_Ink_Pose } , check logcat for specifics.") ;
143
+ Debug . LogError ( $ "MX_Ink: Error getting Pose action name { mxInkPose } , check logcat for specifics.") ;
110
144
}
111
145
}
112
146
0 commit comments