Skip to content

Commit d294042

Browse files
committed
Only polyfill select, not select value
Hand joints are likely better than a 0 or 1 conversion
1 parent 3d8fbb4 commit d294042

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

org.mixedrealitytoolkit.input/Readers/PinchInputReader.cs

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -231,53 +231,34 @@ private void UpdatePinchSelection()
231231
{
232232
using (UpdatePinchSelectionPerfMarker.Auto())
233233
{
234-
// This section accounts for one of "select" and "select value" being bound while the other is polyfilled.
235-
// We can use the data from the bound action to synthesize the other better than the hand joint logic will.
236-
if (!m_isSelectPolyfilled && !m_isTrackingStatePolyfilled)
237-
{
238-
m_fallbackState.value = ReadIsPerformed() ? 1 : 0;
239-
return;
240-
}
241-
else if (!m_isSelectValuePolyfilled && !m_isTrackingStatePolyfilled)
242-
{
243-
bool isPinched = ReadValue() >= (m_fallbackState.isPerformed ? 0.9f : 1.0f);
234+
float pinchAmount;
244235

245-
m_fallbackState.wasPerformedThisFrame = isPinched && !m_fallbackState.isPerformed;
246-
m_fallbackState.wasCompletedThisFrame = !isPinched && m_fallbackState.isPerformed;
247-
m_fallbackState.isPerformed = isPinched;
248-
return;
236+
// This section accounts for "select value" being bound while "select" is polyfilled.
237+
// We can use the data from the bound action to synthesize better than the hand joint logic will.
238+
if (!m_isSelectValuePolyfilled && !m_isTrackingStatePolyfilled)
239+
{
240+
pinchAmount = ReadValue();
249241
}
250-
251-
// If we still don't have an aggregator, then don't update selects.
252-
if (XRSubsystemHelpers.HandsAggregator == null)
242+
// Workaround for missing select actions on devices without interaction profiles
243+
// for hands, such as Varjo and Quest. Should be removed once we have universal
244+
// hand interaction profile(s) across vendors.
245+
else if (XRSubsystemHelpers.HandsAggregator == null
246+
|| !XRSubsystemHelpers.HandsAggregator.TryGetPinchProgress(handNode, out _, out _, out pinchAmount))
253247
{
248+
// If we didn't get pinch data, reset the fallback state.
249+
m_fallbackState = default;
254250
return;
255251
}
256252

257-
// If we got pinch data, write it into our select interaction state.
258-
if (XRSubsystemHelpers.HandsAggregator.TryGetPinchProgress(
259-
handNode,
260-
out _,
261-
out _,
262-
out float pinchAmount))
263-
{
264-
// Workaround for missing select actions on devices without interaction profiles
265-
// for hands, such as Varjo and Quest. Should be removed once we have universal
266-
// hand interaction profile(s) across vendors.
267-
268-
// Debounce the polyfill pinch action value.
269-
bool isPinched = pinchAmount >= (m_fallbackState.isPerformed ? 0.9f : 1.0f);
253+
const float PinchDeactivateThreshold = 0.9f;
254+
const float PinchActivateThreshold = 1.0f;
270255

271-
m_fallbackState.wasPerformedThisFrame = isPinched && !m_fallbackState.isPerformed;
272-
m_fallbackState.wasCompletedThisFrame = !isPinched && m_fallbackState.isPerformed;
273-
m_fallbackState.isPerformed = isPinched;
274-
m_fallbackState.value = pinchAmount;
275-
}
276-
else
277-
{
278-
// If we didn't get pinch data, reset the fallback state.
279-
m_fallbackState = default;
280-
}
256+
// Debounce the polyfill pinch action value.
257+
bool isPinched = pinchAmount >= (m_fallbackState.isPerformed ? PinchDeactivateThreshold : PinchActivateThreshold);
258+
m_fallbackState.wasPerformedThisFrame = isPinched && !m_fallbackState.isPerformed;
259+
m_fallbackState.wasCompletedThisFrame = !isPinched && m_fallbackState.isPerformed;
260+
m_fallbackState.isPerformed = isPinched;
261+
m_fallbackState.value = pinchAmount;
281262
}
282263
}
283264

0 commit comments

Comments
 (0)