float GetMeanFingerConfidence()
        {
            float sumFingerConfidence = 0.0f;

            sumFingerConfidence += OVRConfidenceToLerp(handData.GetFingerConfidence(OVRHand.HandFinger.Thumb));
            sumFingerConfidence += OVRConfidenceToLerp(handData.GetFingerConfidence(OVRHand.HandFinger.Index));
            sumFingerConfidence += OVRConfidenceToLerp(handData.GetFingerConfidence(OVRHand.HandFinger.Middle));
            sumFingerConfidence += OVRConfidenceToLerp(handData.GetFingerConfidence(OVRHand.HandFinger.Ring));
            sumFingerConfidence += OVRConfidenceToLerp(handData.GetFingerConfidence(OVRHand.HandFinger.Pinky));

            return(sumFingerConfidence / 5.0f);
        }
Example #2
0
        protected void UpdateHandData(OVRHand ovrHand, OVRSkeleton ovrSkeleton)
        {
            if (ovrSkeleton != null)
            {
                var bones = ovrSkeleton.Bones;
                foreach (var bone in bones)
                {
                    UpdateBone(bone);
                }

                UpdatePalm();
            }

            CoreServices.InputSystem?.RaiseHandJointsUpdated(InputSource, ControllerHandedness, jointPoses);


            if (IsPinching)
            {
                // If we are already pinching, we make the pinch a bit sticky
                IsPinching = ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index) > 0.85f;
            }
            else
            {
                // If not yet pinching, only consider pinching if finger confidence is high
                IsPinching = ovrHand.GetFingerIsPinching(OVRHand.HandFinger.Index) &&
                             ovrHand.GetFingerConfidence(OVRHand.HandFinger.Index) == OVRHand.TrackingConfidence.High;
            }
        }
Example #3
0
        private void CheckPinchState()
        {
            bool isIndexFingerPinching = ovrHand.GetFingerIsPinching(OVRHand.HandFinger.Index);

            float indexFingerPinchStrength = ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index);

            if (ovrHand.GetFingerConfidence(OVRHand.HandFinger.Index) != OVRHand.TrackingConfidence.High)
            {
                return;
            }

            // finger pinch down
            if (isIndexFingerPinching && indexFingerPinchStrength >= minFingerPinchDownStrength)
            {
                UpdateLine();
                IsPinchingReleased = true;
                return;
            }

            // finger pinch up
            if (IsPinchingReleased)
            {
                AddNewLineRenderer();
                IsPinchingReleased = false;
            }
        }
Example #4
0
    void Update()
    {
        if (_skeletonData.Bones.Count != _proxyHandBones.Length)
        {
            return;
        }

        if (_hand.IsDataValid && _hand.IsDataHighConfidence)
        {
            _proxyHandBones[0]._master.transform.position = _skeletonData.Bones[0].Transform.position;
            _proxyHandBones[0]._master.transform.rotation = _skeletonData.Bones[0].Transform.rotation;
        }
        else
        {
            return;
        }

        for (int bone = 1; bone < _skeletonData.Bones.Count; bone++)
        {
            if (_proxyHandBones[bone]._master && (_hand.GetFingerConfidence(_proxyHandBones[bone]._master._Finger) == OVRHand.TrackingConfidence.High))
            {
                _proxyHandBones[bone]._master.transform.rotation = _skeletonData.Bones[bone].Transform.rotation;
            }
        }
    }
        private void UpdateDataPoses(SkeletonPoseData poseData)
        {
            _handDataAsset.HandScale        = poseData.RootScale;
            _handDataAsset.IsTracked        = _ovrHand.IsTracked;
            _handDataAsset.IsHighConfidence = poseData.IsDataHighConfidence;
            _handDataAsset.IsDominantHand   = _ovrHand.IsDominantHand;
            _handDataAsset.RootPoseOrigin   = _handDataAsset.IsTracked
                ? PoseOrigin.RawTrackedPose
                : PoseOrigin.None;

            for (var fingerIdx = 0; fingerIdx < Constants.NUM_FINGERS; fingerIdx++)
            {
                var  ovrFingerIdx = (OVRHand.HandFinger)fingerIdx;
                bool isPinching   = _ovrHand.GetFingerIsPinching(ovrFingerIdx);
                _handDataAsset.IsFingerPinching[fingerIdx] = isPinching;

                bool isHighConfidence =
                    _ovrHand.GetFingerConfidence(ovrFingerIdx) == OVRHand.TrackingConfidence.High;
                _handDataAsset.IsFingerHighConfidence[fingerIdx] = isHighConfidence;

                float fingerPinchStrength = _ovrHand.GetFingerPinchStrength(ovrFingerIdx);
                _handDataAsset.FingerPinchStrength[fingerIdx] = fingerPinchStrength;
            }

            // Read the poses directly from the poseData, so it isn't in conflict with
            // any modifications that the application makes to OVRSkeleton
            _handDataAsset.Root = new Pose()
            {
                position = poseData.RootPose.Position.FromFlippedZVector3f(),
                rotation = poseData.RootPose.Orientation.FromFlippedZQuatf()
            };

            if (_ovrHand.IsPointerPoseValid)
            {
                _handDataAsset.PointerPoseOrigin = PoseOrigin.RawTrackedPose;
                _handDataAsset.PointerPose       = new Pose(_ovrHand.PointerPose.localPosition,
                                                            _ovrHand.PointerPose.localRotation);
            }
            else
            {
                _handDataAsset.PointerPoseOrigin = PoseOrigin.None;
            }

            // Hand joint rotations X axis needs flipping to get to Unity's coordinate system.
            var bones = poseData.BoneRotations;

            for (int i = 0; i < bones.Length; i++)
            {
                // When using Link in the Unity Editor, the first frame of hand data
                // sometimes contains bad joint data.
                _handDataAsset.Joints[i] = float.IsNaN(bones[i].w)
                    ? Config.HandSkeleton.joints[i].pose.rotation
                    : bones[i].FromFlippedXQuatf();
            }

            _handDataAsset.Joints[0] = WristFixupRotation;
        }
        /// <summary>
        /// Get a float value the finger pinch strength based on the abstract input button
        /// </summary>
        /// <param name="h">Which hand is the axis on</param>
        /// <param name="b">Which button is being pressed</param>
        /// <returns>A float from 0-1 indicating how much the input has been pressed</returns>
        public override float GetAxis(Hand h, Button b)
        {
            var        handObj = (h == Hand.Left) ? leftHand : rightHand;
            OVRHand    hand    = handObj.ActualOvrHand;
            HandFinger finger  = FingerMap(b);

            if (hand && hand.GetFingerConfidence(finger) == TrackingConfidence.High)
            {
                return(hand.GetFingerPinchStrength(finger));
            }

            return(0f);
        }
        /// <summary>
        /// Get whether the correct finger has been pinched based on the abstract input button
        /// </summary>
        /// <param name="h">Which hand is the button on</param>
        /// <param name="b">Which button is being pressed</param>
        /// <returns>A bool indicating whether the given button has been pressed</returns>
        public override bool GetButton(Hand h, Button b)
        {
            var        handObj = (h == Hand.Left) ? leftHand : rightHand;
            OVRHand    hand    = handObj.ActualOvrHand;
            HandFinger finger  = FingerMap(b);

            if (hand && hand.GetFingerConfidence(finger) == TrackingConfidence.High)
            {
                return(hand.GetFingerIsPinching(finger));
            }

            return(false); //null check for hand
        }
        /// <summary>
        /// Get a float value the finger pinch strength based on the abstract input button
        /// </summary>
        /// <param name="h">Which hand is the axis on</param>
        /// <param name="b">Which button is being pressed</param>
        /// <returns>A float from 0-1 indicating how much the input has been pressed</returns>
        public override float GetAxis(Hand h, Button b)
        {
            GameObject handObj = (h == Hand.Left) ? leftHand : rightHand;
            OVRHand    hand    = handObj.GetComponent <OVRHand>();
            HandFinger finger  = FingerMap(b);

            if (hand && hand.GetFingerConfidence(finger) == TrackingConfidence.High)
            {
                return(hand.GetFingerPinchStrength(finger));
            }

            return(0f);
        }
Example #9
0
 // Update is called once per frame
 void Update()
 {
     text.text = RightHand.GetFingerPinchStrength(OVRHand.HandFinger.Index).ToString();
     if (RightHand.GetFingerConfidence(OVRHand.HandFinger.Index) == OVRHand.TrackingConfidence.Low)
     {
         text.text = "0";
     }
     if (LeftHand.GetFingerConfidence(OVRHand.HandFinger.Index) == OVRHand.TrackingConfidence.High)
     {
         Image img = GameObject.Find("Panel").GetComponent <Image>();
         img.color = new Color(img.color.r, img.color.g, img.color.b,
                               LeftHand.GetFingerPinchStrength(OVRHand.HandFinger.Index));
     }
 }
    private void CheckPinchState()
    {
        bool isIndexFingerPinching = ovrHand.GetFingerIsPinching(OVRHand.HandFinger.Index);

        float indexFingerPinchStrength = ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index);

        if (ovrHand.GetFingerConfidence(OVRHand.HandFinger.Index) != OVRHand.TrackingConfidence.High)
        {
            return;
        }

        // finger pinch down
        if (isIndexFingerPinching && indexFingerPinchStrength >= minFingerPinchDownStrength)
        {
            objectToMove.position = boneToTrack.Transform.position;
            return;
        }
    }
Example #11
0
        protected void UpdateHandData(OVRHand ovrHand, OVRSkeleton ovrSkeleton)
        {
            if (ovrSkeleton != null)
            {
                var bones = ovrSkeleton.Bones;
                foreach (var bone in bones)
                {
                    UpdateBone(bone);
                }

                UpdatePalm();
            }

            CoreServices.InputSystem?.RaiseHandJointsUpdated(InputSource, ControllerHandedness, jointPoses);


            if (IsPinching)
            {
                // If we are already pinching, we make the pinch a bit sticky
                IsPinching = ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index) > 0.85f;
            }
            else
            {
                // If not yet pinching, only consider pinching if finger confidence is high
                IsPinching = ovrHand.GetFingerIsPinching(OVRHand.HandFinger.Index) &&
                             ovrHand.GetFingerConfidence(OVRHand.HandFinger.Index) == OVRHand.TrackingConfidence.High;
            }


            // Disable hand if not tracked
            if (handRenderer != null)
            {
                handRenderer.enabled = ovrHand.IsTracked;
            }

            if (MRTKOculusConfig.Instance.UpdateMaterialPinchStrengthValue && handMaterial != null)
            {
                handMaterial.SetFloat(pinchStrengthProp, ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index));
            }
        }
Example #12
0
        void Update()
        {
            updateHandTracking();

            if (IsHandTracking)
            {
                LeftHandConfidence  = LeftHand.GetFingerConfidence(HandFinger.Index);
                RightHandConfidence = RightHand.GetFingerConfidence(HandFinger.Index);

                if (leftSkele != null && leftSkele.Bones != null)
                {
                    leftIndexBone = leftSkele.Bones.FirstOrDefault(x => x.Id == OVRSkeleton.BoneId.Hand_IndexTip);
                    if (leftIndexBone != null)
                    {
                        LeftIndexPosition = leftIndexBone.Transform.position;
                    }
                }

                IsLeftIndexPinching    = LeftHand.GetFingerIsPinching(HandFinger.Index) && LeftHandConfidence == TrackingConfidence.High;
                LeftIndexPinchStrength = LeftHand.GetFingerPinchStrength(HandFinger.Index);

                if (rightSkele && rightSkele.Bones != null)
                {
                    rightIndexBone = rightSkele.Bones.FirstOrDefault(x => x.Id == OVRSkeleton.BoneId.Hand_IndexTip);
                    if (rightIndexBone != null)
                    {
                        RightIndexPosition = rightIndexBone.Transform.position;
                    }
                }

                IsRightIndexPinching    = RightHand.GetFingerIsPinching(HandFinger.Index) && RightHandConfidence == TrackingConfidence.High;
                RightIndexPinchStrength = RightHand.GetFingerPinchStrength(HandFinger.Index);
            }

            updateGrabbers();
        }
Example #13
0
 static private bool IsFingerPinched(OVRHand hand, OVRHand.HandFinger finger)
 {
     return(hand.GetFingerConfidence(finger) == OVRHand.TrackingConfidence.High && hand.GetFingerIsPinching(finger) && hand.GetFingerPinchStrength(finger) >= PinchMaxStrength);
 }
        protected bool UpdateHandData(OVRHand ovrHand, OVRSkeleton ovrSkeleton)
        {
            bool isTracked = ovrHand.IsTracked;

            if (ovrHand.HandConfidence == OVRHand.TrackingConfidence.High)
            {
                _lastHighConfidenceTime = Time.unscaledTime;
            }
            if (ovrHand.HandConfidence == OVRHand.TrackingConfidence.Low)
            {
                if (settingsProfile.MinimumHandConfidence == OVRHand.TrackingConfidence.High)
                {
                    isTracked = false;
                }
                else
                {
                    float lowConfidenceTime = Time.time - _lastHighConfidenceTime;
                    if (settingsProfile.LowConfidenceTimeThreshold > 0 &&
                        settingsProfile.LowConfidenceTimeThreshold < lowConfidenceTime)
                    {
                        isTracked = false;
                    }
                }
            }

            if (ControllerHandedness == Handedness.Left)
            {
                settingsProfile.CurrentLeftHandTrackingConfidence = ovrHand.HandConfidence;
            }
            else
            {
                settingsProfile.CurrentRightHandTrackingConfidence = ovrHand.HandConfidence;
            }

            if (ovrSkeleton != null)
            {
                var bones = ovrSkeleton.Bones;
                foreach (var bone in bones)
                {
                    UpdateBone(bone);
                }

                UpdatePalm();
            }

            HandDefinition?.UpdateHandJoints(jointPoses);

            // Note: After some testing, it seems when moving your hand fast, Oculus's pinch estimation data gets frozen, which leads to stuck pinches.
            // To counter this, we perform a distance check between thumb and index to determine if we should force the pinch to a false state.
            float pinchStrength = HandPoseUtils.CalculateIndexPinch(ControllerHandedness);

            if (pinchStrength == 0.0f)
            {
                IsPinching = false;
            }
            else
            {
                if (IsPinching)
                {
                    // If we are already pinching, we make the pinch a bit sticky
                    IsPinching = pinchStrength > 0.5f;
                }
                else
                {
                    // If not yet pinching, only consider pinching if finger confidence is high
                    IsPinching = pinchStrength > 0.85f && ovrHand.GetFingerConfidence(OVRHand.HandFinger.Index) == OVRHand.TrackingConfidence.High;
                }
            }

            isIndexGrabbing  = HandPoseUtils.IsIndexGrabbing(ControllerHandedness);
            isMiddleGrabbing = HandPoseUtils.IsMiddleGrabbing(ControllerHandedness);


            // Pinch was also used as grab, we want to allow hand-curl grab not just pinch.
            // Determine pinch and grab separately
            if (isTracked)
            {
                IsGrabbing = isIndexGrabbing && isMiddleGrabbing;
            }

            return(isTracked);
        }
Example #15
0
        protected bool UpdateHandData(OVRHand ovrHand, OVRSkeleton ovrSkeleton)
        {
            bool isTracked = ovrHand.IsTracked;

            if (ovrHand.HandConfidence == OVRHand.TrackingConfidence.High)
            {
                _lastHighConfidenceTime = Time.unscaledTime;
            }
            if (ovrHand.HandConfidence == OVRHand.TrackingConfidence.Low)
            {
                if (MRTKOculusConfig.Instance.MinimumHandConfidence == OVRHand.TrackingConfidence.High)
                {
                    isTracked = false;
                }
                else
                {
                    float lowConfidenceTime = Time.time - _lastHighConfidenceTime;
                    if (MRTKOculusConfig.Instance.LowConfidenceTimeThreshold > 0 &&
                        MRTKOculusConfig.Instance.LowConfidenceTimeThreshold < lowConfidenceTime)
                    {
                        isTracked = false;
                    }
                }
            }

            if (ControllerHandedness == Handedness.Left)
            {
                MRTKOculusConfig.Instance.CurrentLeftHandTrackingConfidence = ovrHand.HandConfidence;
            }
            else
            {
                MRTKOculusConfig.Instance.CurrentRightHandTrackingConfidence = ovrHand.HandConfidence;
            }

            // Disable hand if not tracked
            if (handRenderer != null)
            {
                handRenderer.enabled = isTracked;
            }

            if (ovrSkeleton != null)
            {
                var bones = ovrSkeleton.Bones;
                foreach (var bone in bones)
                {
                    UpdateBone(bone);
                }

                UpdatePalm();
            }

            CoreServices.InputSystem?.RaiseHandJointsUpdated(InputSource, ControllerHandedness, jointPoses);

            // Note: After some testing, it seems when moving your hand fast, Oculus's pinch estimation data gets frozen, which leads to stuck pinches.
            // To counter this, we perform a distance check between thumb and index to determine if we should force the pinch to a false state.
            float pinchStrength;

            if (AreIndexAndThumbFarApart())
            {
                pinchStrength = 0f;
                IsPinching    = false;
            }
            else
            {
                pinchStrength = ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index);
                if (IsPinching)
                {
                    // If we are already pinching, we make the pinch a bit sticky
                    IsPinching = ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index) > 0.85f;
                }
                else
                {
                    // If not yet pinching, only consider pinching if finger confidence is high
                    IsPinching = ovrHand.GetFingerIsPinching(OVRHand.HandFinger.Index) &&
                                 ovrHand.GetFingerConfidence(OVRHand.HandFinger.Index) == OVRHand.TrackingConfidence.High;
                }
            }

            isIndexGrabbing  = HandPoseUtils.IsIndexGrabbing(ControllerHandedness);
            isMiddleGrabbing = HandPoseUtils.IsMiddleGrabbing(ControllerHandedness);
            isThumbGrabbing  = HandPoseUtils.IsThumbGrabbing(ControllerHandedness);

            // Hand Curl Properties:
            float indexFingerCurl  = HandPoseUtils.IndexFingerCurl(ControllerHandedness);
            float middleFingerCurl = HandPoseUtils.MiddleFingerCurl(ControllerHandedness);
            float ringFingerCurl   = HandPoseUtils.RingFingerCurl(ControllerHandedness);
            float pinkyFingerCurl  = HandPoseUtils.PinkyFingerCurl(ControllerHandedness);

            // Pinch was also used as grab, we want to allow hand-curl grab not just pinch.
            // Determine pinch and grab separately
            if (isTracked)
            {
                IsGrabbing = isIndexGrabbing && isMiddleGrabbing;
            }

            if (MRTKOculusConfig.Instance.UpdateMaterialPinchStrengthValue && handMaterial != null)
            {
                float gripStrength = indexFingerCurl + middleFingerCurl + ringFingerCurl + pinkyFingerCurl;
                gripStrength /= 4.0f;
                gripStrength  = gripStrength > 0.8f ? 1.0f : gripStrength;

                pinchStrength = Mathf.Max(pinchStrength, gripStrength);
                handMaterial.SetFloat(pinchStrengthProp, pinchStrength);
            }
            return(isTracked);
        }