Example #1
0
        void MatchBones(Transform steamVRBone, Transform leapBone, BoneBasis basis,
                        Quaternion leapOrientation, int depth = 0)
        {
            if (depth == 0)
            {
                leapBone.transform.position = steamVRBone.transform.position;
            }
            else
            {
                controllerHand.SetTransformWithConstraint(leapBone, steamVRBone.transform.position, GlobalRotationFromBasis(steamVRBone, basis) * leapOrientation);
            }

            if (steamVRBone.childCount == leapBone.childCount)
            {
                if (steamVRBone.childCount == 1)
                {
                    MatchBones(steamVRBone.GetChild(0), leapBone.GetChild(0), basis, leapOrientation, depth + 1);
                }
            }
            else
            {
                Debug.LogError("Mismatch between steamVR and leap child count. Steam Bone:" + steamVRBone + " leap bone: " + leapBone);
                Debug.Break();
            }
        }
Example #2
0
 void MatchBone(Transform oculusBone, Transform leapBone, BoneBasis basis,
                Quaternion leapOrientation)
 {
     controllerHand.SetTransformWithConstraint(leapBone,
                                               oculusBone.transform.position,
                                               GlobalRotationFromBasis(oculusBone, basis) * leapOrientation);
 }
        private void DrawBones(Transform parent, BoneBasis basis)
        {
            DrawBasis(parent, basis);

            for (int i = 0; i < parent.childCount; i++)
            {
                Gizmos.color = Color.white;
                Gizmos.DrawLine(parent.transform.position,
                                parent.GetChild(i).position);

                DrawBones(parent.GetChild(i), basis);
            }
        }
Example #4
0
        protected override void Awake()
        {
            base.Awake();

            hand     = controllerTransform.GetComponentInChildren <OVRHand>();
            skeleton = hand.GetComponent <OVRSkeleton>();

            GetControllerHashes();

            fingerBasis = new BoneBasis()
            {
                Forward = fingerForward, Up = fingerUp
            };
        }
        protected void DrawBasis(Transform bone, BoneBasis basis)
        {
            Quaternion rotation = GlobalRotationFromBasis(bone, basis);

            Vector3 up, forward, right;

            up      = rotation * Vector3.up;
            forward = rotation * Vector3.forward;
            right   = rotation * Vector3.right;

            Gizmos.color = Color.yellow;
            Gizmos.DrawLine(bone.position, bone.position + (up * 0.025f));
            Gizmos.color = Color.red;
            Gizmos.DrawLine(bone.position, bone.position + (right * 0.025f));
            Gizmos.color = Color.blue;
            Gizmos.DrawLine(bone.position, bone.position + (forward * 0.025f));
        }
Example #6
0
        private void DrawPalm(Transform bone, BoneBasis basis)
        {
            DrawBasis(bone, basis);

            Quaternion rotation = Quaternion.LookRotation(bone.transform.TransformDirection(basis.Forward),
                                                          basis.Up);

            Vector3 up, forward, right;

            up      = rotation * Vector3.up;
            forward = rotation * Vector3.forward;
            right   = rotation * Vector3.right;

            Vector3 palmPosition = wrist.TransformPoint(palmOffset);

            Gizmos.color = Color.black;
            Gizmos.DrawLine(palmPosition, palmPosition + forward * 0.04f);
        }
 protected Quaternion GlobalRotationFromBasis(Transform bone, BoneBasis basis)
 {
     return(Quaternion.LookRotation(bone.TransformDirection(basis.Forward),
                                    bone.TransformDirection(basis.Up)));
 }
Example #8
0
        void DoSkeletalTracking()
        {
            // do any pre-flight checks here
            // confidence maybe?
            if (true)
            {
                handAnimator.enabled = true;
                BoneBasis basis = new BoneBasis()
                {
                    Forward = fingerForward, Up = fingerUp
                };

                // do our wrist pose
                OVRBone wristBone = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_WristRoot];

                Vector3    wristPos             = wristBone.Transform.position;
                Quaternion wristboneOrientation = controllerHand.GetLocalBasis();

                /*controllerHand.Wrist.SetPositionAndRotation(wristBone.Transform.position,
                 *      GlobalRotationFromBasis(wristBone.Transform, basis) * wristboneOrientation);*/
                controllerHand.Wrist.rotation = GlobalRotationFromBasis(wristBone.Transform, basis) * wristboneOrientation;

                // do our fingers. Skip metacarpals, Oculus does not provide them.
                // we could possibly compute the missing bone rotation, if needed.
                // do the index bones
                OVRBone   indexProximalBone = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Index1];
                OVRBone   indexMedialBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Index2];
                OVRBone   indexDistalBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Index3];
                Transform indexProximal     = controllerHand.IndexMetacarpal.GetChild(0);
                Transform indexMedial       = indexProximal.GetChild(0);
                Transform indexDistal       = indexMedial.GetChild(0);

                MatchBone(indexProximalBone.Transform, indexProximal, basis, wristboneOrientation);
                MatchBone(indexMedialBone.Transform, indexMedial, basis, wristboneOrientation);
                MatchBone(indexDistalBone.Transform, indexDistal, basis, wristboneOrientation);

                // do the middle bones
                OVRBone   middleProximalBone = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Middle1];
                OVRBone   middleMedialBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Middle2];
                OVRBone   middleDistalBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Middle3];
                Transform middleProximal     = controllerHand.MiddleMetacarpal.GetChild(0);
                Transform middleMedial       = middleProximal.GetChild(0);
                Transform middleDistal       = middleMedial.GetChild(0);

                MatchBone(middleProximalBone.Transform, middleProximal, basis, wristboneOrientation);
                MatchBone(middleMedialBone.Transform, middleMedial, basis, wristboneOrientation);
                MatchBone(middleDistalBone.Transform, middleDistal, basis, wristboneOrientation);

                // do the ring bones
                OVRBone   ringProximalBone = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Ring1];
                OVRBone   ringMedialBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Ring2];
                OVRBone   ringDistalBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Ring3];
                Transform ringProximal     = controllerHand.RingMetacarpal.GetChild(0);
                Transform ringMedial       = ringProximal.GetChild(0);
                Transform ringDistal       = ringMedial.GetChild(0);

                MatchBone(ringProximalBone.Transform, ringProximal, basis, wristboneOrientation);
                MatchBone(ringMedialBone.Transform, ringMedial, basis, wristboneOrientation);
                MatchBone(ringDistalBone.Transform, ringDistal, basis, wristboneOrientation);

                // do the pinky bones
                OVRBone   pinkyMetacarpalBone = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Pinky0];
                OVRBone   pinkyProximalBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Pinky1];
                OVRBone   pinkyMedialBone     = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Pinky2];
                OVRBone   pinkyDistalBone     = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Pinky2];
                Transform pinkyMetacarpal     = controllerHand.PinkyMetacarpal;
                Transform pinkyPromial        = pinkyMetacarpal.GetChild(0);
                Transform pinkyMedial         = pinkyPromial.GetChild(0);
                Transform pinkyDistal         = pinkyMedial.GetChild(0);

                MatchBone(pinkyMetacarpalBone.Transform, pinkyMetacarpal, basis, wristboneOrientation);
                MatchBone(pinkyProximalBone.Transform, pinkyPromial, basis, wristboneOrientation);
                MatchBone(pinkyMedialBone.Transform, pinkyMedial, basis, wristboneOrientation);
                MatchBone(pinkyDistalBone.Transform, pinkyDistal, basis, wristboneOrientation);

                // do the thumb bones
                OVRBone   thumbRootBone       = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Thumb0];
                OVRBone   thumbMetacarpalBone = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Thumb1];
                OVRBone   thumbProximalBone   = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Thumb2];
                OVRBone   thumbDistalBone     = skeleton.Bones[(int)OVRSkeleton.BoneId.Hand_Thumb3];
                Transform thumbMetacarpal     = controllerHand.ThumbMetacarpal;             // naming gets weird here, sorry.
                Transform thumbProximal       = thumbMetacarpal.GetChild(0);
                Transform thumbDistal         = thumbProximal.GetChild(0);

                MatchBone(thumbMetacarpalBone.Transform, thumbMetacarpal, basis, wristboneOrientation);
                MatchBone(thumbProximalBone.Transform, thumbProximal, basis, wristboneOrientation);
                MatchBone(thumbDistalBone.Transform, thumbDistal, basis, wristboneOrientation);
            }
        }