Esempio n. 1
0
        protected virtual void InitFingersData()
        {
            Animator animator = QuickSingletonManager.GetInstance <QuickVRManager>().GetAnimatorSource();

            QuickHumanFingers[] fingers = QuickHumanTrait.GetHumanFingers();
            int numFingers = fingers.Length;

            _handFingerConfidence = new int[numFingers];
            _vrNodeFingers        = new QuickVRNode[numFingers * NUM_BONES_PER_FINGER];
            _tBoneFingers         = new Transform[numFingers * NUM_BONES_PER_FINGER];

            for (int i = 0; i < numFingers; i++)
            {
                _handFingerConfidence[i] = NUM_FRAMES_CONFIDENCE;
                List <QuickHumanBodyBones> fingerBones = QuickHumanTrait.GetBonesFromFinger(fingers[i], IsLeft());
                for (int j = 0; j < NUM_BONES_PER_FINGER; j++)
                {
                    int       fingerBoneID = (i * NUM_BONES_PER_FINGER) + j;
                    Transform tBone        = animator.GetBoneTransform(fingerBones[j]);

                    _vrNodeFingers[fingerBoneID] = _playArea.GetVRNode(fingerBones[j]);
                    _tBoneFingers[fingerBoneID]  = tBone;
                }
            }
        }
Esempio n. 2
0
        protected virtual void UpdateVRNodeFingers()
        {
            if (IsTracked() && QuickVRManager._handTrackingMode == QuickVRManager.HandTrackingMode.Controllers)
            {
                //Update the nodes of the fingers
                foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
                {
                    List <QuickHumanBodyBones> fingerBones = QuickHumanTrait.GetBonesFromFinger(f, _isLeft);
                    for (int i = 0; i < QuickHumanTrait.NUM_BONES_PER_FINGER; i++)
                    {
                        QuickVRNode nFinger = QuickSingletonManager.GetInstance <QuickVRPlayArea>().GetVRNode(fingerBones[i]);

                        //The finger is tracked.
                        Transform t = _handAnimator[(int)f][i]; // .GetBoneFingerTransform(f, i);
                        nFinger.transform.position = t.position;
                        nFinger.transform.rotation = t.rotation;

                        //Correct the rotation
                        //if (IsLeft())
                        //{
                        //    nFinger.transform.Rotate(Vector3.right, 180, Space.Self);
                        //    nFinger.transform.Rotate(Vector3.up, -90, Space.Self);
                        //}
                        //else
                        //{
                        //    nFinger.transform.Rotate(Vector3.up, 90, Space.Self);
                        //}

                        nFinger.SetTracked(true);
                    }
                }
            }
        }
Esempio n. 3
0
        protected virtual void UpdateVRNodeFingers()
        {
            if (IsInitialized())
            {
                if (!_physicsInitialized)
                {
                    CreatePhysics();
                    _physicsInitialized = true;
                }

                if (!_fingersDataInitialized)
                {
                    InitFingersData();
                    _fingersDataInitialized = true;
                }

                //Update the nodes of the fingers
                foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
                {
                    _handFingerConfidence[(int)f] = IsDataHighConfidence ? Mathf.Min(_handFingerConfidence[(int)f] + 1, NUM_FRAMES_CONFIDENCE) : 0;

                    for (int i = 0; i < NUM_BONES_PER_FINGER; i++)
                    {
                        int         boneID  = ((int)f) * NUM_BONES_PER_FINGER + i;
                        QuickVRNode nFinger = _vrNodeFingers[boneID]; //_playArea.GetVRNode(fingerBones[i]);

                        if (IsDataHighConfidenceFinger(f))
                        {
                            //The finger is tracked.
                            OVRSkeleton.BoneId ovrBoneID = _ovrFingerBones[boneID];
                            Transform          ovrBone   = GetOVRBoneTransform(ovrBoneID);
                            nFinger.transform.position = ovrBone.position;
                            nFinger.transform.rotation = ovrBone.rotation;

                            //Correct the rotation
                            if (IsLeft())
                            {
                                nFinger.transform.Rotate(Vector3.right, 180, Space.Self);
                                nFinger.transform.Rotate(Vector3.up, -90, Space.Self);
                            }
                            else
                            {
                                nFinger.transform.Rotate(Vector3.up, 90, Space.Self);
                            }


                            //nFinger.SetTracked(true);
                        }
                        else
                        {
                            //The finger is not tracked. Restore the last valid local rotation.
                            //nFinger.SetTracked(false);
                        }

                        nFinger.SetTracked(true);
                    }
                }
            }
        }
Esempio n. 4
0
        private static void Init()
        {
            _allJoints = QuickUtils.ParseEnum <QuickHumanBodyBones, TrackedJointBody>();
            foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
            {
                _allJoints.AddRange(QuickHumanTrait.GetBonesFromFinger(f, true));
                _allJoints.AddRange(QuickHumanTrait.GetBonesFromFinger(f, false));
            }

            foreach (TrackedJointBody j in QuickUtils.GetEnumValues <TrackedJointBody>())
            {
                _toTrackedJointBody[QuickUtils.ParseEnum <QuickHumanBodyBones>(j.ToString())] = j;
            }
        }
Esempio n. 5
0
 protected virtual void InitBoneFingers()
 {
     _boneFingers = new List <KeyValuePair <Transform, Transform> >();
     foreach (bool b in new bool[] { true, false })
     {
         foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
         {
             List <QuickHumanBodyBones> fingerBones = QuickHumanTrait.GetBonesFromFinger(f, b);
             for (int i = 0; i < fingerBones.Count; i++)
             {
                 QuickHumanBodyBones fBoneID = fingerBones[i];
                 _boneFingers.Add(new KeyValuePair <Transform, Transform>(_animator.GetBoneTransform(fBoneID), _vrPlayArea.GetVRNode(fBoneID).GetTrackedObject().transform));
             }
         }
     }
 }
Esempio n. 6
0
        protected override void UpdateIKFingers()
        {
            if (_vrPlayArea)
            {
                //if (_boneFingers == null)
                //{
                //    InitBoneFingers();
                //}

                //for (int j = 0; j < _boneFingers.Count; j+= 4)
                //{
                //    if (_boneFingers[j].Key != null)
                //    {
                //        for (int i = 0; i < 3; i++)
                //        {
                //            if ((i == 0 && (j == 0 || j == 20)) && QuickVRManager._handTrackingMode == QuickVRManager.HandTrackingMode.Controllers)
                //            {
                //                //HACK
                //                //Avoid applying the rotation to the thumb distal fingers as the results look weird. Look for a better method
                //                //of transfering the bone rotations when using the controllers.
                //                continue;
                //            }
                //            ApplyFingerRotation(_boneFingers[j + i], _boneFingers[j + i + 1]);
                //        }
                //    }
                //}


                //foreach (bool b in new bool[] { true, false })
                //{
                //    foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
                //    {
                //        List<QuickHumanBodyBones> fingerBones = QuickHumanTrait.GetBonesFromFinger(f, b);
                //        List<Quaternion> initialFingerBonesLocalRotations = new List<Quaternion>();

                //        for (int i = 0; i < fingerBones.Count - 1; i++)
                //        {
                //            QuickHumanBodyBones fBoneID = fingerBones[i];
                //            initialFingerBonesLocalRotations.Add(_animator.GetBoneTransform(fBoneID).localRotation);

                //            if (_animator.GetBoneTransform(fBoneID) && _vrPlayArea.GetVRNode(fBoneID).IsTracked())
                //            {
                //                ApplyFingerRotation(fBoneID, fingerBones[i + 1]);
                //            }
                //        }

                //        //At this point the finger is correctly aligned. Set the targets to match this.
                //        //HumanBodyBones boneID = (HumanBodyBones)fingerBones[2];
                //        //QuickIKSolver ikSolver = GetIKSolver(boneID);
                //        //Transform tBone = _animator.GetBoneTransform(boneID);

                //        //ikSolver._targetLimb.position = tBone.position;
                //        //ikSolver._targetLimb.GetChild(0).rotation = tBone.rotation;
                //        //ikSolver._targetHint.position = ikSolver._boneMid.position + (ikSolver._boneMid.position - ikSolver._boneUpper.position) + (ikSolver._boneMid.position - ikSolver._boneLimb.position);

                //        ////Restore the rotation of the bone fingers
                //        //ikSolver._boneUpper.localRotation = initialFingerBonesLocalRotations[0];
                //        //ikSolver._boneMid.localRotation = initialFingerBonesLocalRotations[1];
                //        //ikSolver._boneLimb.localRotation = initialFingerBonesLocalRotations[2];
                //    }
                //}



                //foreach (bool b in new bool[] { true, false })
                //{
                //    foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
                //    {
                //        List<QuickHumanBodyBones> fingerBones = QuickHumanTrait.GetBonesFromFinger(f, b);
                //        List<Quaternion> initialFingerBonesLocalRotations = new List<Quaternion>();

                //        for (int i = 0; i < fingerBones.Count - 1; i++)
                //        {
                //            QuickHumanBodyBones fBoneID = fingerBones[i];
                //            initialFingerBonesLocalRotations.Add(_animator.GetBoneTransform(fBoneID).localRotation);

                //            if (_animator.GetBoneTransform(fBoneID) && _vrPlayArea.GetVRNode(fBoneID).IsTracked())
                //            {
                //                ApplyFingerRotation(fBoneID, fingerBones[i + 1]);
                //            }
                //        }

                //        //At this point the finger is correctly aligned. Set the targets to match this.
                //        //HumanBodyBones boneID = (HumanBodyBones)fingerBones[2];
                //        //QuickIKSolver ikSolver = GetIKSolver(boneID);
                //        //Transform tBone = _animator.GetBoneTransform(boneID);

                //        //ikSolver._targetLimb.position = tBone.position;
                //        //ikSolver._targetLimb.GetChild(0).rotation = tBone.rotation;
                //        //ikSolver._targetHint.position = ikSolver._boneMid.position + (ikSolver._boneMid.position - ikSolver._boneUpper.position) + (ikSolver._boneMid.position - ikSolver._boneLimb.position);

                //        ////Restore the rotation of the bone fingers
                //        //ikSolver._boneUpper.localRotation = initialFingerBonesLocalRotations[0];
                //        //ikSolver._boneMid.localRotation = initialFingerBonesLocalRotations[1];
                //        //ikSolver._boneLimb.localRotation = initialFingerBonesLocalRotations[2];
                //    }
                //}

                //foreach (bool isLeft in new bool[] { true, false })
                //{
                //    foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
                //    {
                //        float fLength = _vrPlayArea.GetFingerLength(f, isLeft);
                //        if (fLength > 0)
                //        {
                //            List<QuickHumanBodyBones> fingerBones = QuickHumanTrait.GetBonesFromFinger(f, isLeft);
                //            QuickVRNode n0 = _vrPlayArea.GetVRNode(fingerBones[0]);
                //            QuickVRNode n1 = _vrPlayArea.GetVRNode(fingerBones[1]);
                //            QuickVRNode n2 = _vrPlayArea.GetVRNode(fingerBones[2]);

                //            QuickIKSolver ikSolver = GetIKSolver((HumanBodyBones)fingerBones[2]);

                //            if (n0.IsTracked() && n2.IsTracked())
                //            {
                //                float sf = ikSolver.GetChainLength() / fLength;
                //                Vector3 v = sf * (n2.transform.position - n0.transform.position);

                //                ikSolver._targetLimb.position = ikSolver._boneUpper.position + v;
                //                ikSolver._targetHint.position = ikSolver._boneMid.position + (n1.transform.position - n0.transform.position) + (n1.transform.position - n2.transform.position);
                //            }
                //        }
                //    }
                //}

                foreach (bool isLeft in new bool[] { true, false })
                {
                    foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
                    {
                        List <QuickHumanBodyBones> fingerBones = QuickHumanTrait.GetBonesFromFinger(f, isLeft);
                        QuickVRNode n0 = _vrPlayArea.GetVRNode(fingerBones[0]);
                        QuickVRNode n1 = _vrPlayArea.GetVRNode(fingerBones[1]);
                        QuickVRNode n2 = _vrPlayArea.GetVRNode(fingerBones[2]);

                        if (n0.IsTracked() && n1.IsTracked() && n2.IsTracked())
                        {
                            QuickIKSolver ikSolver = GetIKSolver((HumanBodyBones)fingerBones[2]);

                            Vector3 v = (n1.transform.position - n0.transform.position).normalized;
                            Vector3 w = (n2.transform.position - n1.transform.position).normalized;

                            ikSolver._targetLimb.position = ikSolver._boneUpper.position + v * ikSolver.GetUpperLength() + w * ikSolver.GetMidLength();
                            ikSolver._targetLimb.rotation = n2.transform.rotation;
                            ikSolver._targetHint.position = ikSolver._boneMid.position + n1.transform.up * DEFAULT_TARGET_HINT_FINGER_DISTANCE;
                            ikSolver._targetHint.rotation = n1.transform.rotation;
                            //ikSolver._targetHint.position = ikSolver._boneMid.position + (n1.transform.position - n0.transform.position) + (n1.transform.position - n2.transform.position);
                        }
                    }
                }
            }

            base.UpdateIKFingers();
        }