-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracking): add finger tracking (#12)
- Loading branch information
Showing
10 changed files
with
838 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"conventionalCommits.scopes": [ | ||
"release" | ||
"release", | ||
"tracking" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace TTIK.Ik.FingerTracking; | ||
|
||
class CustomHandUpdater | ||
{ | ||
public static FingerType[] ALL_FINGER_TYPES = [FingerType.Thumb, FingerType.Index, FingerType.Middle, FingerType.Ring, FingerType.Pinky]; | ||
|
||
public Dictionary<FingerType, Finger> fingers = new Dictionary<FingerType, Finger>(); | ||
|
||
public void OnBoneTransformsUpdated(FingerType fingerType, float value) | ||
{ | ||
if (fingers.TryGetValue(fingerType, out var finger)) | ||
{ | ||
finger.CurlFinger(value); | ||
} | ||
} | ||
} | ||
|
||
// Not currently used but kept for reference or future change from curl to actual finger movement | ||
// https://github.com/ValveSoftware/openvr/wiki/Hand-Skeleton | ||
enum Bone | ||
{ | ||
Root = 0, | ||
Wrist, | ||
|
||
Thumb0, | ||
Thumb1, | ||
Thumb2, | ||
Thumb3, | ||
|
||
IndexFinger0, | ||
IndexFinger1, | ||
IndexFinger2, | ||
IndexFinger3, | ||
IndexFinger4, | ||
|
||
MiddleFinger0, | ||
MiddleFinger1, | ||
MiddleFinger2, | ||
MiddleFinger3, | ||
MiddleFinger4, | ||
|
||
RingFinger0, | ||
RingFinger1, | ||
RingFinger2, | ||
RingFinger3, | ||
RingFinger4, | ||
|
||
PinkyFinger0, | ||
PinkyFinger1, | ||
PinkyFinger2, | ||
PinkyFinger3, | ||
PinkyFinger4, | ||
|
||
Aux_Thumb, | ||
Aux_IndexFinger, | ||
Aux_MiddleFinger, | ||
Aux_RingFinger, | ||
Aux_PinkyFinger, | ||
Count | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace TTIK.Ik.FingerTracking; | ||
|
||
public class Finger | ||
{ | ||
private Vector3 axis = Vector3.back; | ||
private float totalCurl = 180; | ||
private Dictionary<Transform, float> bones = new Dictionary<Transform, float>(); | ||
private Dictionary<Transform, Quaternion> originalRotations = new Dictionary<Transform, Quaternion>(); | ||
|
||
public Finger(Vector3? axis = null, float totalCurl = 180) | ||
{ | ||
this.axis = axis ?? this.axis; | ||
this.totalCurl = totalCurl; | ||
} | ||
|
||
public Finger(Dictionary<Transform, float> bones, Vector3? axis = null, float totalCurl = 180) : this(axis, totalCurl) | ||
{ | ||
this.bones = bones; | ||
} | ||
|
||
public Finger WithBone(Transform transform) | ||
{ | ||
AddBone(transform); | ||
return this; | ||
} | ||
|
||
public Finger WithBone(Transform transform, float factor) | ||
{ | ||
AddBone(transform, factor); | ||
return this; | ||
} | ||
|
||
public void AddBone(Transform transform) | ||
{ | ||
AddBone(transform, 1); | ||
} | ||
|
||
public void AddBone(Transform transform, float factor) | ||
{ | ||
bones.Add(transform, factor); | ||
originalRotations.Add(transform, transform.localRotation); | ||
} | ||
|
||
public void CurlFinger(float factor) | ||
{ | ||
var relativeFactor = factor / bones.Values.Sum(); | ||
foreach (var (bone, boneFactor) in bones) | ||
{ | ||
var originalRotation = originalRotations[bone]; | ||
var combinedFactor = boneFactor * relativeFactor; | ||
// Rotate around forward axis | ||
bone.localRotation = originalRotation * Quaternion.AngleAxis(totalCurl * combinedFactor, axis); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace TTIK.Ik.FingerTracking; | ||
|
||
public enum FingerType | ||
{ | ||
Thumb = 0, | ||
Index, | ||
Middle, | ||
Ring, | ||
Pinky | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace TTIK.Ik.FingerTracking; | ||
|
||
public enum HandType | ||
{ | ||
Left = 0, | ||
Right | ||
} |
Oops, something went wrong.