Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Implement grip threshold profile setting (#767)
Browse files Browse the repository at this point in the history
* Implement grip threshold profile setting

* Bump version to v0.2.3

* Update submodules

* Fix tooltips for grip threshold range

* Update submodules

Co-authored-by: Stephen Hodgson <hodgson.designs@gmail.com>
  • Loading branch information
FejZa and StephenHodgson authored Jan 25, 2021
1 parent 75506c0 commit fac015b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ private void BakePoseData()
var handData = poseDefinition.ToHandData();

// Intialize processors needed.
var gripPostProcessor = new HandGripPostProcessor();
var gripPostProcessor = new HandGripPostProcessor(.8f);

// Process the hand data, most hand data processors
// will ignore the hand data if it is not tracked, so we
// have to temporarily fake it's tracking state and then reset it.
handData.TrackingState = Definitions.Devices.TrackingState.Tracked;
gripPostProcessor.PostProcess(Handedness.Right, handData);
handData = gripPostProcessor.PostProcess(Handedness.Right, handData);
handData.TrackingState = Definitions.Devices.TrackingState.NotTracked;

isGripping.boolValue = handData.IsGripping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BaseMixedRealityHandControllerDataProviderProfileInspector : BaseMi
{
private static readonly GUIContent handTrackingSettingsFoldoutHeader = new GUIContent("Hand Tracking Settings");

private SerializedProperty gripThreshold;
private SerializedProperty renderingMode;
private SerializedProperty handPhysicsEnabled;
private SerializedProperty useTriggers;
Expand All @@ -29,6 +30,7 @@ protected override void OnEnable()
{
base.OnEnable();

gripThreshold = serializedObject.FindProperty(nameof(gripThreshold));
renderingMode = serializedObject.FindProperty(nameof(renderingMode));
handPhysicsEnabled = serializedObject.FindProperty(nameof(handPhysicsEnabled));
useTriggers = serializedObject.FindProperty(nameof(useTriggers));
Expand Down Expand Up @@ -59,13 +61,17 @@ public override void OnInspectorGUI()
{
EditorGUI.indentLevel++;

EditorGUILayout.LabelField("Hand Rendering Settings");
EditorGUILayout.LabelField("General Hand Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(gripThreshold);
EditorGUILayout.Space();

EditorGUILayout.LabelField("Hand Rendering Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(renderingMode);
EditorGUILayout.Space();
EditorGUI.indentLevel--;

EditorGUILayout.LabelField("Hand Physics Settings");
EditorGUILayout.LabelField("Hand Physics Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(handPhysicsEnabled);
EditorGUILayout.PropertyField(useTriggers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SimulatedHandControllerDataProviderProfileInspector : SimulatedCont
private static readonly GUIContent SimulatedHandSettingsFoldoutHeader = new GUIContent("Simulated Hand Tracking Settings");
private static readonly GUIContent handPoseAnimationSpeedLabel = new GUIContent("Hand Pose Animation Speed");

private SerializedProperty gripThreshold;
private SerializedProperty renderingMode;
private SerializedProperty handPhysicsEnabled;
private SerializedProperty useTriggers;
Expand All @@ -31,6 +32,7 @@ protected override void OnEnable()
{
base.OnEnable();

gripThreshold = serializedObject.FindProperty(nameof(gripThreshold));
renderingMode = serializedObject.FindProperty(nameof(renderingMode));
handPhysicsEnabled = serializedObject.FindProperty(nameof(handPhysicsEnabled));
useTriggers = serializedObject.FindProperty(nameof(useTriggers));
Expand Down Expand Up @@ -64,13 +66,17 @@ public override void OnInspectorGUI()
{
EditorGUI.indentLevel++;

EditorGUILayout.LabelField("Hand Rendering Settings");
EditorGUILayout.LabelField("General Hand Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(gripThreshold);
EditorGUILayout.Space();

EditorGUILayout.LabelField("Hand Rendering Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(renderingMode);
EditorGUILayout.Space();
EditorGUI.indentLevel--;

EditorGUILayout.LabelField("Hand Physics Settings");
EditorGUILayout.LabelField("Hand Physics Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(handPhysicsEnabled);
EditorGUILayout.PropertyField(useTriggers);
Expand All @@ -83,7 +89,7 @@ public override void OnInspectorGUI()
EditorGUILayout.Space();
EditorGUI.indentLevel--;

EditorGUILayout.LabelField("Simulated Poses");
EditorGUILayout.LabelField("Simulated Poses", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
handPoseAnimationSpeed.floatValue = EditorGUILayout.Slider(handPoseAnimationSpeedLabel, handPoseAnimationSpeed.floatValue, 1, 10);
EditorGUILayout.Space();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MixedRealityInputSystemProfileInspector : MixedRealityServiceProfil
private SerializedProperty drawDebugPointingRays;
private SerializedProperty debugPointingRayColors;

private SerializedProperty gripThreshold;
private SerializedProperty renderingMode;
private SerializedProperty handPhysicsEnabled;
private SerializedProperty useTriggers;
Expand Down Expand Up @@ -65,6 +66,7 @@ protected override void OnEnable()
drawDebugPointingRays = serializedObject.FindProperty(nameof(drawDebugPointingRays));
debugPointingRayColors = serializedObject.FindProperty(nameof(debugPointingRayColors));

gripThreshold = serializedObject.FindProperty(nameof(gripThreshold));
renderingMode = serializedObject.FindProperty(nameof(renderingMode));
handPhysicsEnabled = serializedObject.FindProperty(nameof(handPhysicsEnabled));
useTriggers = serializedObject.FindProperty(nameof(useTriggers));
Expand Down Expand Up @@ -163,6 +165,9 @@ public override void OnInspectorGUI()
EditorGUILayout.HelpBox("Global hand tracking options applied to all platforms that support hand tracking. You may override these globals per platform in the platform's hand controller data provider profile.", MessageType.Info);
EditorGUI.indentLevel++;
EditorGUILayout.Space();
EditorGUILayout.LabelField("General Hand Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(gripThreshold);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Hand Rendering Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(renderingMode);
EditorGUILayout.Space();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ namespace XRTK.Definitions.Controllers.Hands
/// </summary>
public abstract class BaseHandControllerDataProviderProfile : BaseMixedRealityControllerDataProviderProfile
{
[SerializeField]
[Range(.5f, 1f)]
[Tooltip("Threshold in range [0.5, 1] that defines when a hand is considered to be grabing.")]
private float gripThreshold = .8f;

/// <summary>
/// Threshold in range [0, 1] that defines when a hand is considered to be grabing.
/// </summary>
public float GripThreshold => gripThreshold;

[SerializeField]
[Tooltip("Defines what kind of data should be aggregated for the hands rendering.")]
private HandRenderingMode renderingMode = HandRenderingMode.Joints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ public class SimulatedHandControllerDataProviderProfile : SimulatedControllerDat
/// </summary>
public float HandPoseAnimationSpeed => handPoseAnimationSpeed;

[SerializeField]
[Range(.5f, 1f)]
[Tooltip("Threshold in range [0.5, 1] that defines when a hand is considered to be grabing.")]
private float gripThreshold = .8f;

/// <summary>
/// Threshold in range [0, 1] that defines when a hand is considered to be grabing.
/// </summary>
public float GripThreshold => gripThreshold;

[SerializeField]
[Tooltip("Defines what kind of data should be aggregated for the hands rendering.")]
private HandRenderingMode renderingMode = HandRenderingMode.Joints;
Expand Down
10 changes: 10 additions & 0 deletions Runtime/Definitions/InputSystem/MixedRealityInputSystemProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public SystemType GazeProviderType

#region Global Hand Options

[SerializeField]
[Range(.5f, 1f)]
[Tooltip("Threshold in range [0.5, 1] that defines when a hand is considered to be grabing.")]
private float gripThreshold = .8f;

/// <summary>
/// Threshold in range [0, 1] that defines when a hand is considered to be grabing.
/// </summary>
public float GripThreshold => gripThreshold;

[SerializeField]
[Tooltip("Defines what kind of data should be aggregated for the hands rendering.")]
private HandRenderingMode renderingMode = HandRenderingMode.Joints;
Expand Down
5 changes: 3 additions & 2 deletions Runtime/Providers/Controllers/Hands/HandDataPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public sealed class HandDataPostProcessor : IHandDataPostProcessor
/// Creates a new instance of the hand data post processor.
/// </summary>
/// <param name="trackedPoses">Pose recognizer instance to use for pose recognition.</param>
public HandDataPostProcessor(IReadOnlyList<HandControllerPoseProfile> trackedPoses)
/// <param name="isGrippingThreshold">Threshold in range [0, 1] that defines when a hand is considered to be grabing.</param>
public HandDataPostProcessor(IReadOnlyList<HandControllerPoseProfile> trackedPoses, float isGrippingThreshold)
{
TrackedPoseProcessor = new HandTrackedPosePostProcessor(trackedPoses);
GripPostProcessor = new HandGripPostProcessor();
GripPostProcessor = new HandGripPostProcessor(isGrippingThreshold);
}

private const float IS_POINTING_DOTP_THRESHOLD = .1f;
Expand Down
16 changes: 12 additions & 4 deletions Runtime/Providers/Controllers/Hands/HandGripPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace XRTK.Providers.Controllers.Hands
/// </summary>
public sealed class HandGripPostProcessor : IHandDataPostProcessor
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="isGrippingThreshold">Threshold in range [0, 1] that defines when a hand is considered to be grabing.</param>
public HandGripPostProcessor(float isGrippingThreshold)
{
this.isGrippingThreshold = isGrippingThreshold;
}

private const float CURL_THUMB_METACARPAL_LOW_END_ANGLE = 70f;
private const float CURL_THUMB_METACARPAL_HIGH_END_ANGLE = 100f;
private const float CURL_THUMB_METACARPAL_DISTANCE = CURL_THUMB_METACARPAL_HIGH_END_ANGLE - CURL_THUMB_METACARPAL_LOW_END_ANGLE;
Expand Down Expand Up @@ -53,11 +62,10 @@ public sealed class HandGripPostProcessor : IHandDataPostProcessor

private const float CURL_TOTAL_INTERMEDIATE_DISTANCE = CURL_LITTLE_INTERMEDIATE_DISTANCE + CURL_RING_INTERMEDIATE_DISTANCE + CURL_MIDDLE_INTERMEDIATE_DISTANCE + CURL_INDEX_INTERMEDIATE_DISTANCE;

private const float IS_GRIPPING_CURL_THRESHOLD = .9f;
private const float IS_GRIPPING_INDEX_CURL_THRESHOLD = .8f;

private const bool DEBUG_LOG_VALUES_TO_CONSOLE = false;

private readonly float isGrippingThreshold;

/// <inheritdoc />
public HandData PostProcess(Handedness handedness, HandData handData)
{
Expand Down Expand Up @@ -133,7 +141,7 @@ public HandData PostProcess(Handedness handedness, HandData handData)
// Hand is gripping if the grip strength passed the threshold. But we are also taking
// the index curl into account explicitly, this helps avoiding the pinch gesture being
// considered gripping as well.
handData.IsGripping = handData.GripStrength >= IS_GRIPPING_CURL_THRESHOLD && indexCurlStrength >= IS_GRIPPING_INDEX_CURL_THRESHOLD;
handData.IsGripping = handData.GripStrength >= isGrippingThreshold && indexCurlStrength >= isGrippingThreshold * .9f;

if (Debug.isDebugBuild && DEBUG_LOG_VALUES_TO_CONSOLE)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public SimulatedHandControllerDataProvider(string name, uint priority, Simulated
? profile.BoundsMode
: globalSettingsProfile.BoundsMode;

var isGrippingThreshold = profile.GripThreshold != globalSettingsProfile.GripThreshold
? profile.GripThreshold
: globalSettingsProfile.GripThreshold;

if (profile.TrackedPoses != null && profile.TrackedPoses.Count > 0)
{
TrackedPoses = profile.TrackedPoses.Count != globalSettingsProfile.TrackedPoses.Count
Expand Down Expand Up @@ -76,7 +80,7 @@ public SimulatedHandControllerDataProvider(string name, uint priority, Simulated
JitterAmount,
DefaultDistance);

postProcessor = new HandDataPostProcessor(TrackedPoses);
postProcessor = new HandDataPostProcessor(TrackedPoses, isGrippingThreshold);
}

private readonly SimulatedHandDataConverter leftHandConverter;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Mixed Reality",
"DI"
],
"version": "0.2.2",
"version": "0.2.3",
"unity": "2019.4",
"license": "MIT",
"author": "XRTK Team (https://github.com/XRTK)",
Expand Down

0 comments on commit fac015b

Please sign in to comment.