Skip to content

Commit 42596af

Browse files
authored
Fix issue where WMR controllers weren't reporting spatial data in "controller" mode when hand joints were enabled (#10547)
* Only continue through UpdateSixDofData if we actually obtained SixDofData * Update OpenXRDeviceManager.cs
1 parent 2ab47b7 commit 42596af

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

Assets/MRTK/Providers/OpenXR/Scripts/OpenXRDeviceManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ protected override SupportedControllerType GetCurrentControllerType(InputDevice
273273
return base.GetCurrentControllerType(inputDevice);
274274
}
275275

276-
#endregion Controller Utilities
276+
#endregion Controller Utilities
277277

278-
#region Gesture implementation
278+
#region Gesture implementation
279279

280280
#if MSFT_OPENXR && WINDOWS_UWP
281281
private void ReadProfile()
@@ -520,6 +520,6 @@ private GenericXRSDKController FindMatchingController(GestureHandedness gestureH
520520
}
521521
#endif // MSFT_OPENXR && WINDOWS_UWP
522522

523-
#endregion Gesture implementation
523+
#endregion Gesture implementation
524524
}
525525
}

Assets/MRTK/Providers/XRSDK/Controllers/GenericXRSDKController.cs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ public virtual void UpdateController(InputDevice inputDevice)
9393

9494
protected virtual void UpdateSixDofData(InputDevice inputDevice)
9595
{
96-
UpdateSourceData(inputDevice);
96+
if (!UpdateSourceData(inputDevice))
97+
{
98+
return;
99+
}
100+
97101
UpdateVelocity(inputDevice);
98102

99103
if (TrackingState == TrackingState.Tracked && LastControllerPose != CurrentControllerPose)
@@ -129,33 +133,43 @@ protected virtual void UpdateSixDofData(InputDevice inputDevice)
129133
/// Update the source input from the device.
130134
/// </summary>
131135
/// <param name="inputDevice">The InputDevice retrieved from the platform.</param>
132-
public void UpdateSourceData(InputDevice inputDevice)
136+
/// <returns>Whether position or rotation was successfully updated.</returns>
137+
public bool UpdateSourceData(InputDevice inputDevice)
133138
{
134139
using (UpdateSourceDataPerfMarker.Auto())
135140
{
136-
var lastState = TrackingState;
141+
TrackingState lastState = TrackingState;
137142
LastControllerPose = CurrentControllerPose;
138143

139144
// Check for position and rotation.
140-
IsPositionAvailable = inputDevice.TryGetFeatureValue(CommonUsages.devicePosition, out CurrentControllerPosition);
141-
IsPositionApproximate = false;
145+
bool isPositionAvailable = inputDevice.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 position);
146+
bool isRotationAvailable = inputDevice.TryGetFeatureValue(CommonUsages.deviceRotation, out Quaternion rotation);
142147

143-
IsRotationAvailable = inputDevice.TryGetFeatureValue(CommonUsages.deviceRotation, out CurrentControllerRotation);
148+
if (isPositionAvailable || isRotationAvailable)
149+
{
150+
IsPositionAvailable = isPositionAvailable;
151+
IsPositionApproximate = false;
152+
IsRotationAvailable = isRotationAvailable;
144153

145-
// Devices are considered tracked if we receive position OR rotation data from the sensors.
146-
TrackingState = (IsPositionAvailable || IsRotationAvailable) ? TrackingState.Tracked : TrackingState.NotTracked;
154+
// Devices are considered tracked if we receive position OR rotation data from the sensors.
155+
TrackingState = (IsPositionAvailable || IsRotationAvailable) ? TrackingState.Tracked : TrackingState.NotTracked;
147156

148-
CurrentControllerPosition = MixedRealityPlayspace.TransformPoint(CurrentControllerPosition);
149-
CurrentControllerRotation = MixedRealityPlayspace.Rotation * CurrentControllerRotation;
157+
CurrentControllerPosition = MixedRealityPlayspace.TransformPoint(position);
158+
CurrentControllerRotation = MixedRealityPlayspace.Rotation * rotation;
150159

151-
CurrentControllerPose.Position = CurrentControllerPosition;
152-
CurrentControllerPose.Rotation = CurrentControllerRotation;
160+
CurrentControllerPose.Position = CurrentControllerPosition;
161+
CurrentControllerPose.Rotation = CurrentControllerRotation;
153162

154-
// Raise input system events if it is enabled.
155-
if (lastState != TrackingState)
156-
{
157-
CoreServices.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
163+
// Raise input system events if it is enabled.
164+
if (lastState != TrackingState)
165+
{
166+
CoreServices.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
167+
}
168+
169+
return true;
158170
}
171+
172+
return false;
159173
}
160174
}
161175

@@ -165,13 +179,12 @@ public void UpdateVelocity(InputDevice inputDevice)
165179
{
166180
using (UpdateVelocityPerfMarker.Auto())
167181
{
168-
Vector3 newVelocity;
169-
if (inputDevice.TryGetFeatureValue(CommonUsages.deviceVelocity, out newVelocity))
182+
if (inputDevice.TryGetFeatureValue(CommonUsages.deviceVelocity, out Vector3 newVelocity))
170183
{
171184
Velocity = newVelocity;
172185
}
173-
Vector3 newAngularVelocity;
174-
if (inputDevice.TryGetFeatureValue(CommonUsages.deviceAngularVelocity, out newAngularVelocity))
186+
187+
if (inputDevice.TryGetFeatureValue(CommonUsages.deviceAngularVelocity, out Vector3 newAngularVelocity))
175188
{
176189
AngularVelocity = newAngularVelocity;
177190
}

0 commit comments

Comments
 (0)