Skip to content

Commit

Permalink
Merge pull request #1616 from ultraleap/feature/Simplify_specific_Bon…
Browse files Browse the repository at this point in the history
…e_and_Finger_access

Feature/simplify specific bone and finger access
  • Loading branch information
MattGrayUL committed May 31, 2024
2 parents 93f9580 + d8f534b commit f349afb
Show file tree
Hide file tree
Showing 50 changed files with 340 additions and 548 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,16 @@ float[] Confidence_RelativeJointRot(float[] confidences, Transform deviceOrigin,
confidences = new float[VectorHand.NUM_JOINT_POSITIONS];
}

foreach (var finger in hand.Fingers)
foreach (var finger in hand.fingers)
{
for (int bone_idx = 0; bone_idx < 4; bone_idx++)
{
int key = (int)finger.Type * 4 + bone_idx;

Vector3 jointPos = finger.Bone((Bone.BoneType)bone_idx).NextJoint;
Vector3 jointPos = finger.GetBone((Bone.BoneType)bone_idx).NextJoint;
Vector3 jointNormalVector = new Vector3();
if ((int)finger.Type == 0) jointNormalVector = finger.Bone((Bone.BoneType)bone_idx).Rotation * Vector3.right;
else jointNormalVector = finger.Bone((Bone.BoneType)bone_idx).Rotation * Vector3.up * -1;
if ((int)finger.Type == 0) jointNormalVector = finger.GetBone((Bone.BoneType)bone_idx).Rotation * Vector3.right;
else jointNormalVector = finger.GetBone((Bone.BoneType)bone_idx).Rotation * Vector3.up * -1;

float angle = Vector3.Angle(jointPos - deviceOrigin.position, jointNormalVector);

Expand All @@ -604,13 +604,13 @@ float[] Confidence_relativeJointRotToPalmRot(float[] confidences, Transform devi
confidences = new float[VectorHand.NUM_JOINT_POSITIONS];
}

foreach (var finger in hand.Fingers)
foreach (var finger in hand.fingers)
{
for (int bone_idx = 0; bone_idx < 4; bone_idx++)
{
int key = (int)finger.Type * 4 + bone_idx;

Vector3 jointNormalVector = finger.Bone((Bone.BoneType)bone_idx).Rotation * Vector3.up * -1;
Vector3 jointNormalVector = finger.GetBone((Bone.BoneType)bone_idx).Rotation * Vector3.up * -1;

float angle = Vector3.Angle(hand.PalmNormal, jointNormalVector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public float[] Confidence_JointOcclusion(float[] confidences, Transform deviceOr
// and how many pixels of a joint would be seen if the joint was not occluded at all (in optimalPixelsCount)
int[] pixelsSeenCount = new int[confidences.Length];
int[] optimalPixelsCount = new int[confidences.Length];
foreach (var finger in hand.Fingers)
foreach (var finger in hand.fingers)
{
for (int j = 0; j < 4; j++)
{
Expand All @@ -158,7 +158,7 @@ public float[] Confidence_JointOcclusion(float[] confidences, Transform deviceOr

// get the joint position from the given hand and use it to calculate the screen position of the joint's center and
// a point on the outside border of the joint (both in pixel coordinates)
Vector3 jointPos = finger.Bone((Leap.Bone.BoneType)j).NextJoint;
Vector3 jointPos = finger.GetBone((Leap.Bone.BoneType)j).NextJoint;
Vector3 screenPosCenter = cam.WorldToScreenPoint(jointPos);
Vector3 screenPosSphereOutside = cam.WorldToScreenPoint(jointPos + cam.transform.right * jointRadius);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void Update()
{
for (int k = 0; k < 4; k++)
{
sourceHandPoints.Add(sourceHand.Fingers[j].bones[k].Center);
targetHandPoints.Add(targetHand.Fingers[j].bones[k].Center);
sourceHandPoints.Add(sourceHand.fingers[j].bones[k].Center);
targetHandPoints.Add(targetHand.fingers[j].bones[k].Center);
}
}

Expand Down
8 changes: 0 additions & 8 deletions Packages/Tracking Preview/Examples~/Example Assets.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Packages/Tracking Preview/Examples~/Hand Recorder.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Packages/Tracking Preview/Examples~/HandRays.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Packages/Tracking Preview/Examples~/Locomotion.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Packages/Tracking Preview/Examples~/UI Input Examples.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Packages/Tracking Preview/Examples~/XRControllerSupport.meta

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ private void PositionGem()
if (_pinchStartTimeCurrent > 0)
{
_pinchItem.position = Vector3.Lerp(_pinchStartPosition,
Vector3.Lerp(_pinchedHand.Fingers[0].TipPosition, _pinchedHand.Fingers[1].TipPosition, 0.5f),
Vector3.Lerp(_pinchedHand.fingers[0].TipPosition, _pinchedHand.fingers[1].TipPosition, 0.5f),
Mathf.InverseLerp(_pinchStartTime, 0, _pinchStartTimeCurrent));
_pinchItem.rotation = Quaternion.Lerp(_pinchStartRotation,
_rayRotation,
Mathf.InverseLerp(_pinchStartTime, 0, _pinchStartTimeCurrent));
}
else
{
_pinchItem.position = Vector3.Lerp(_pinchedHand.Fingers[0].TipPosition, _pinchedHand.Fingers[1].TipPosition, 0.5f);
_pinchItem.position = Vector3.Lerp(_pinchedHand.fingers[0].TipPosition, _pinchedHand.fingers[1].TipPosition, 0.5f);
_pinchItem.rotation = _rayRotation;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ private void Start()
/// </summary>
private float DistanceOfTipToPointer(Hand hand)
{
var tipPosition = hand.Fingers[(int)Finger.FingerType.TYPE_INDEX]
.Bone(Bone.BoneType.TYPE_DISTAL).NextJoint;
var tipPosition = hand.fingers[(int)Finger.FingerType.INDEX]
.GetBone(Bone.BoneType.DISTAL).NextJoint;

var pointerTransform = transform;
return -pointerTransform.transform.InverseTransformPoint(tipPosition).z * pointerTransform.transform.lossyScale.z - module.TactilePadding;
Expand Down Expand Up @@ -760,27 +760,27 @@ private bool GetLookPointerEventData(Hand hand, Vector3 origin, bool forceTipRay
tipRaycast = true;

var farthest = 0f;
pointerPosition = hand.GetIndex().TipPosition;
pointerPosition = hand.Index.TipPosition;
for (var i = 1; i < 3; i++)
{
var fingerDistance = Vector3.Distance(mainCamera.transform.position,
hand.Fingers[i].TipPosition);
hand.fingers[i].TipPosition);
var fingerExtension =
Mathf.Clamp01(Vector3.Dot(
hand.Fingers[i].Direction,
hand.fingers[i].Direction,
leapDataProvider.CurrentFrame.Hands[0].Direction)) / 1.5f;

if (fingerDistance > farthest && fingerExtension > 0.5f)
{
farthest = fingerDistance;
pointerPosition = hand.Fingers[i].TipPosition;
pointerPosition = hand.fingers[i].TipPosition;
}
}
}
else
{
//Raycast through the knuckle of the finger
pointerPosition = mainCamera.transform.position - origin + hand.Fingers[(int)Finger.FingerType.TYPE_INDEX].Bone(Bone.BoneType.TYPE_METACARPAL).Center;
pointerPosition = mainCamera.transform.position - origin + hand.fingers[(int)Finger.FingerType.INDEX].GetBone(Bone.BoneType.METACARPAL).Center;
}

//Set the Raycast Direction and Delta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,15 @@ private Hand GenerateControllerHand()
SetFingerSizes(ref h, 0.013f);

// Thumb
RotateFinger(h.Fingers[0], this.Thumb);
RotateFinger(h.fingers[0], this.Thumb);

// index Finger
RotateFinger(h.Fingers[1], this.IndexFinger);
RotateFinger(h.fingers[1], this.IndexFinger);

// Grip Fingers
RotateFinger(h.Fingers[2], this.MiddleFinger);
RotateFinger(h.Fingers[3], this.RingFinger);
RotateFinger(h.Fingers[4], this.PinkyFinger);
RotateFinger(h.fingers[2], this.MiddleFinger);
RotateFinger(h.fingers[3], this.RingFinger);
RotateFinger(h.fingers[4], this.PinkyFinger);

h.Transform(_currentPosition, _currentRotation);

Expand All @@ -469,11 +469,11 @@ private Hand GenerateControllerHand()

private void SetFingerSizes(ref Hand hand, float boneWidth)
{
for (int i = 0; i < hand.Fingers.Count; i++)
for (int i = 0; i < hand.fingers.Length; i++)
{
for (int j = 0; j < hand.Fingers[i].bones.Length; j++)
for (int j = 0; j < hand.fingers[i].bones.Length; j++)
{
hand.Fingers[i].bones[j].Width = boneWidth;
hand.fingers[i].bones[j].Width = boneWidth;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Packages/Tracking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Improved XRHands support for Meta Aim Input Actions
- XRLeapProviderManager renamed LEAP_DIRECT to ULTRALEAP
- Accessors for Hand.Finger, Hand.Bone and Finger.Bone
- Renamed BoneType enum entries to remove redundancies

### Fixed
- Issue with the method signature for LeapPixelToRectilinearEx
Expand Down
2 changes: 1 addition & 1 deletion Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Arm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Arm : Bone, IEquatable<Arm>
direction,
length,
width,
BoneType.TYPE_METACARPAL, //ignored for arms
BoneType.METACARPAL, //ignored for arms
rotation)
{ }

Expand Down
12 changes: 6 additions & 6 deletions Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Bone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Bone : IEquatable<Bone>
/// </summary>
public Bone()
{
Type = BoneType.TYPE_INVALID;
Type = BoneType.UNKNOWN;
}

/// <summary>
Expand Down Expand Up @@ -185,11 +185,11 @@ public LeapTransform Basis
/// </summary>
public enum BoneType
{
TYPE_INVALID = -1,
TYPE_METACARPAL = 0,
TYPE_PROXIMAL = 1,
TYPE_INTERMEDIATE = 2,
TYPE_DISTAL = 3
UNKNOWN = -1,
METACARPAL = 0,
PROXIMAL = 1,
INTERMEDIATE = 2,
DISTAL = 3
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static Hand CopyFrom(this Hand hand, ref LEAP_HAND leapHand, long frameI
hand.FrameId = frameId;
hand.Id = (int)leapHand.id;

hand.Arm.CopyFrom(leapHand.arm, Bone.BoneType.TYPE_INVALID);
hand.Arm.CopyFrom(leapHand.arm, Bone.BoneType.UNKNOWN);

hand.Confidence = leapHand.confidence;
hand.GrabStrength = leapHand.grab_strength;
Expand All @@ -92,11 +92,11 @@ private static Hand CopyFrom(this Hand hand, ref LEAP_HAND leapHand, long frameI
hand.Direction = leapHand.palm.direction.ToVector3();
hand.WristPosition = hand.Arm.NextJoint;

hand.Fingers[0].CopyFrom(leapHand.thumb, Leap.Finger.FingerType.TYPE_THUMB, hand.Id, hand.TimeVisible);
hand.Fingers[1].CopyFrom(leapHand.index, Leap.Finger.FingerType.TYPE_INDEX, hand.Id, hand.TimeVisible);
hand.Fingers[2].CopyFrom(leapHand.middle, Leap.Finger.FingerType.TYPE_MIDDLE, hand.Id, hand.TimeVisible);
hand.Fingers[3].CopyFrom(leapHand.ring, Leap.Finger.FingerType.TYPE_RING, hand.Id, hand.TimeVisible);
hand.Fingers[4].CopyFrom(leapHand.pinky, Leap.Finger.FingerType.TYPE_PINKY, hand.Id, hand.TimeVisible);
hand.fingers[0].CopyFrom(leapHand.thumb, Leap.Finger.FingerType.THUMB, hand.Id, hand.TimeVisible);
hand.fingers[1].CopyFrom(leapHand.index, Leap.Finger.FingerType.INDEX, hand.Id, hand.TimeVisible);
hand.fingers[2].CopyFrom(leapHand.middle, Leap.Finger.FingerType.MIDDLE, hand.Id, hand.TimeVisible);
hand.fingers[3].CopyFrom(leapHand.ring, Leap.Finger.FingerType.RING, hand.Id, hand.TimeVisible);
hand.fingers[4].CopyFrom(leapHand.pinky, Leap.Finger.FingerType.PINKY, hand.Id, hand.TimeVisible);

hand.TransformToUnityUnits();

Expand All @@ -123,10 +123,10 @@ private static Finger CopyFrom(this Finger finger, LEAP_DIGIT leapBone, Finger.F
Bone intermediate = finger.bones[2];
Bone distal = finger.bones[3];

metacarpal.CopyFrom(leapBone.metacarpal, Leap.Bone.BoneType.TYPE_METACARPAL);
proximal.CopyFrom(leapBone.proximal, Leap.Bone.BoneType.TYPE_PROXIMAL);
intermediate.CopyFrom(leapBone.intermediate, Leap.Bone.BoneType.TYPE_INTERMEDIATE);
distal.CopyFrom(leapBone.distal, Leap.Bone.BoneType.TYPE_DISTAL);
metacarpal.CopyFrom(leapBone.metacarpal, Leap.Bone.BoneType.METACARPAL);
proximal.CopyFrom(leapBone.proximal, Leap.Bone.BoneType.PROXIMAL);
intermediate.CopyFrom(leapBone.intermediate, Leap.Bone.BoneType.INTERMEDIATE);
distal.CopyFrom(leapBone.distal, Leap.Bone.BoneType.DISTAL);

finger.TipPosition = distal.NextJoint;
finger.Direction = intermediate.Direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Hand CopyFrom(this Hand hand, Hand source)

for (int i = 5; i-- != 0;)
{
hand.Fingers[i].CopyFrom(source.Fingers[i]);
hand.fingers[i].CopyFrom(source.fingers[i]);
}

return hand;
Expand Down
26 changes: 11 additions & 15 deletions Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Finger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class Finger
/// </summary>
public Bone[] bones = new Bone[4];

public Bone Metacarpal => bones[0];
public Bone Proximal => bones[1];
public Bone Intermediate => bones[2];
public Bone Distal => bones[3];

/// <summary>
/// Constructs a finger.
///
Expand Down Expand Up @@ -82,15 +87,6 @@ public Finger()
TimeVisible = timeVisible;
}

/// <summary>
/// The bone at a given bone index on this finger.
/// @since 2.0
/// </summary>
public Bone Bone(Bone.BoneType boneIx)
{
return bones[(int)boneIx];
}

/// <summary>
/// A string containing a brief, human readable description of the Finger object.
/// @since 1.0
Expand Down Expand Up @@ -178,12 +174,12 @@ public override string ToString()
/// </summary>
public enum FingerType
{
TYPE_THUMB = 0,
TYPE_INDEX = 1,
TYPE_MIDDLE = 2,
TYPE_RING = 3,
TYPE_PINKY = 4,
TYPE_UNKNOWN = -1
THUMB = 0,
INDEX = 1,
MIDDLE = 2,
RING = 3,
PINKY = 4,
UNKNOWN = -1
}
}
}

0 comments on commit f349afb

Please sign in to comment.