Skip to content

Commit dd6d1b9

Browse files
committed
Merge pull request #10206 from jonathoncobb/jonathoncobb/fingertip-pointer
Add option to move grasp point to fingertip
1 parent 39b8ee9 commit dd6d1b9

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

Assets/MRTK/SDK/Features/UX/Scripts/Pointers/SpherePointer.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace Microsoft.MixedReality.Toolkit.Input
1111
[AddComponentMenu("Scripts/MRTK/SDK/SpherePointer")]
1212
public class SpherePointer : BaseControllerPointer, IMixedRealityNearPointer
1313
{
14+
private enum GraspPointPlacement
15+
{
16+
BetweenIndexFingerAndThumb,
17+
IndexFingertip,
18+
}
19+
1420
private SceneQueryType raycastMode = SceneQueryType.SphereOverlap;
1521

1622
/// <inheritdoc />
@@ -146,10 +152,14 @@ public float NearObjectSmoothingFactor
146152
[Tooltip("Whether to ignore colliders that may be near the pointer, but not actually in the visual FOV. This can prevent accidental grabs, and will allow hand rays to turn on when you may be near a grabbable but cannot see it. Visual FOV is defined by cone centered about display center, radius equal to half display height.")]
147153
private bool ignoreCollidersNotInFOV = true;
148154

155+
[SerializeField]
156+
[Tooltip("Location on the hand where a grasp is triggered (apllies to IMixedRealityHand only)")]
157+
private GraspPointPlacement graspPointPlacement = GraspPointPlacement.BetweenIndexFingerAndThumb;
158+
149159
/// <summary>
150160
/// Whether to ignore colliders that may be near the pointer, but not actually in the visual FOV.
151-
/// This can prevent accidental grabs, and will allow hand rays to turn on when you may be near
152-
/// a grabbable but cannot see it. Visual FOV is defined by cone centered about display center,
161+
/// This can prevent accidental grabs, and will allow hand rays to turn on when you may be near
162+
/// a grabbable but cannot see it. Visual FOV is defined by cone centered about display center,
153163
/// radius equal to half display height.
154164
/// </summary>
155165
public bool IgnoreCollidersNotInFOV
@@ -227,7 +237,7 @@ public override void OnPreSceneQuery()
227237

228238
/// <summary>
229239
/// Gets the position of where grasp happens
230-
/// For IMixedRealityHand it's the average of index and thumb.
240+
/// For IMixedRealityHand it's determined by <see cref="graspPointPlacement"/> (either the average of index and thumb or the fingertip).
231241
/// For any other IMixedRealityController, return just the pointer origin
232242
/// </summary>
233243
public bool TryGetNearGraspPoint(out Vector3 result)
@@ -241,10 +251,19 @@ public bool TryGetNearGraspPoint(out Vector3 result)
241251
{
242252
if (hand.TryGetJoint(TrackedHandJoint.IndexTip, out MixedRealityPose index) && index != null)
243253
{
244-
if (hand.TryGetJoint(TrackedHandJoint.ThumbTip, out MixedRealityPose thumb) && thumb != null)
254+
switch (graspPointPlacement)
245255
{
246-
result = 0.5f * (index.Position + thumb.Position);
247-
return true;
256+
case GraspPointPlacement.BetweenIndexFingerAndThumb:
257+
if (hand.TryGetJoint(TrackedHandJoint.ThumbTip, out MixedRealityPose thumb) && thumb != null)
258+
{
259+
result = 0.5f * (index.Position + thumb.Position);
260+
return true;
261+
}
262+
break;
263+
264+
case GraspPointPlacement.IndexFingertip:
265+
result = index.Position;
266+
return true;
248267
}
249268
}
250269
}
@@ -267,7 +286,7 @@ public bool TryGetNearGraspPoint(out Vector3 result)
267286

268287
/// <summary>
269288
/// Because pointers shouldn't be able to interact with objects that are "behind" it, it is necessary to determine the forward axis of the pointer when making interaction checks.
270-
///
289+
///
271290
/// For example, a grab pointer's axis should is the result of Vector3.Lerp(palm forward axis, palm to index finger axis).
272291
///
273292
/// This method provides a mechanism to get this normalized forward axis.
@@ -347,7 +366,7 @@ public bool TryGetNormalToNearestSurface(out Vector3 normal)
347366
private class SpherePointerQueryInfo
348367
{
349368
/// <summary>
350-
/// How many colliders are near the point from the latest call to TryUpdateQueryBufferForLayerMask
369+
/// How many colliders are near the point from the latest call to TryUpdateQueryBufferForLayerMask.
351370
/// </summary>
352371
private int numColliders;
353372

@@ -382,7 +401,7 @@ private class SpherePointerQueryInfo
382401
public bool ignoreBoundsHandlesForQuery = false;
383402

384403
/// <summary>
385-
/// The grabbable near the QueryRadius.
404+
/// The grabbable near the QueryRadius.
386405
/// </summary>
387406
private NearInteractionGrabbable grabbable;
388407

0 commit comments

Comments
 (0)