From 54ba006027f478883c403fa81809f089f31fcac0 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Wed, 21 May 2025 23:17:06 -0400 Subject: [PATCH] finger flexion sourced from oriels --- sk_demo/src/Rig.cs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/sk_demo/src/Rig.cs b/sk_demo/src/Rig.cs index 44e4130..6d9d9b4 100644 --- a/sk_demo/src/Rig.cs +++ b/sk_demo/src/Rig.cs @@ -51,4 +51,42 @@ public class Rig held = down; } } + + public float FingerFlex(Hand hand, FingerId id, float deadzone = 0.15f) + { + float fingerFlex = (Vec3.Dot( + Vec3.Direction( + hand.Get(id, JointId.Tip).position, + hand.Get(id, JointId.KnuckleMinor).position + ), + Vec3.Direction( + hand.Get(id, JointId.KnuckleMid).position, + hand.Get(id, JointId.KnuckleMajor).position + ) + ) + 1f) / 2; + float fingerTrim = 0f + deadzone; // 180° + return Math.Max(fingerFlex - fingerTrim, 0f) / (1 - fingerTrim); + } + + public float KnuckleFlex(Hand hand, FingerId id, float deadzone = 0.15f) + { + float knuckleFlex = (Vec3.Dot( + Vec3.Direction( + hand.Get(id, JointId.KnuckleMid).position, + hand.Get(id, JointId.KnuckleMajor).position + ), + Vec3.Direction( + hand.Get(id, JointId.KnuckleMajor).position, + hand.Get(id, JointId.Root).position + ) + ) + 1f) / 2; + float knuckleTrim = 0.5f + deadzone; // 90° + return Math.Max(knuckleFlex - knuckleTrim, 0f) / (1 - knuckleTrim); + } + + public float Flexion(Hand hand, FingerId id, float deadzone = 0.15f) + { + float flexion = KnuckleFlex(hand, id, deadzone) * FingerFlex(hand, id, deadzone); + return flexion * flexion; // why assume this curve? + } } \ No newline at end of file