Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address thumb and wrist rotation issues for xrhands #1525

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool PopulateXRHandFromLeap(Hand leapHand, ref Pose rootPose, ref NativeArray<XR
}

Pose palmPose = CalculatePalmPose(leapHand);
Pose wristPose = CalculateWristPose(leapHand);
Pose wristPose = CalculateWristPose(leapHand, palmPose.position);

rootPose = wristPose;
Handedness handedness = (Handedness)((int)leapHand.GetChirality() + 1); // +1 as unity has "invalid" handedness while we do not
Expand All @@ -181,14 +181,32 @@ bool PopulateXRHandFromLeap(Hand leapHand, ref Pose rootPose, ref NativeArray<XR
{
var bone = finger.bones[i];

handJoints[jointIndex] = XRHandProviderUtility.CreateJoint(handedness,
XRHandJointTrackingState.Pose,
XRHandJointIDUtility.FromIndex(jointIndex),
new Pose(bone.PrevJoint, bone.Rotation));
if (i == 1)
{
// Rotate the first joint of the thumb to better suit the OpenXR spec
Quaternion rot = bone.Rotation * Quaternion.Euler(0,
leapHand.IsLeft ? 25.9f : -25.9f,
leapHand.IsLeft ? -63.45f : 63.45f);

handJoints[jointIndex] = XRHandProviderUtility.CreateJoint(handedness,
XRHandJointTrackingState.Pose,
XRHandJointIDUtility.FromIndex(jointIndex),
new Pose(bone.PrevJoint, rot));
}
else
{
handJoints[jointIndex] = XRHandProviderUtility.CreateJoint(handedness,
XRHandJointTrackingState.Pose,
XRHandJointIDUtility.FromIndex(jointIndex),
new Pose(bone.PrevJoint, bone.Rotation));
}


jointIndex++;
}

var distal = finger.Bone(Bone.BoneType.TYPE_DISTAL);

handJoints[jointIndex] = XRHandProviderUtility.CreateJoint(handedness,
XRHandJointTrackingState.Pose,
XRHandJointIDUtility.FromIndex(jointIndex),
Expand Down Expand Up @@ -229,14 +247,13 @@ Pose CalculatePalmPose(Hand leapHand)
return palmPose;
}

Pose CalculateWristPose(Hand leapHand)
Pose CalculateWristPose(Hand leapHand, Vector3 newPalmPos)
{
Vector3 wristUp = leapHand.GetMiddle().Bone(Bone.BoneType.TYPE_METACARPAL).Rotation * Vector3.up;
Vector3 wristForward = leapHand.GetMiddle().Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint - leapHand.WristPosition;
Vector3 palmToWrist = leapHand.WristPosition - leapHand.PalmPosition;

Pose wristPose = new Pose();
wristPose.position = leapHand.WristPosition;
wristPose.rotation = Quaternion.LookRotation(wristForward, wristUp);
wristPose.position = newPalmPos + palmToWrist;
wristPose.rotation = leapHand.Rotation;

return wristPose;
}
Expand Down Expand Up @@ -285,4 +302,4 @@ static bool DoesDescriptorExist()
public class LeapHandsSubsystem : XRHandSubsystem
{

}
}