Example #1
0
 public override float CurrentFlex()
 {
     if (IsUsingHands)
     {
         return(Math.Max(trackedHand.GetFingerPinchStrength(OVRHand.HandFinger.Index),
                         trackedHand.GetFingerPinchStrength(OVRHand.HandFinger.Middle)));
     }
     else
     {
         return(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touch));
     }
 }
Example #2
0
 public float CurrentFlex()
 {
     if (trackedHand && trackedHand.IsTracked)
     {
         GrabThresold = grabThresoldHand;
         return(Math.Max(trackedHand.GetFingerPinchStrength(OVRHand.HandFinger.Index),
                         trackedHand.GetFingerPinchStrength(OVRHand.HandFinger.Middle)));
     }
     else
     {
         GrabThresold = grabThresoldController;
         return(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_controller));
     }
 }
Example #3
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 #4
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 #5
0
        public void UpdateState(OVRHand hand, Interactable currFocusedInteractable)
        {
            float pinchStrength = hand.GetFingerPinchStrength(OVRHand.HandFinger.Index);
            bool  isPinching    = Mathf.Abs(PINCH_STRENGTH_THRESHOLD - pinchStrength) < Mathf.Epsilon;
            var   oldPinchState = _currPinchState;

            switch (oldPinchState)
            {
            case PinchState.PinchUp:
                // can only be in pinch up for a single frame, so consider
                // next frame carefully
                if (isPinching)
                {
                    _currPinchState = PinchState.PinchDown;
                    if (currFocusedInteractable != _firstFocusedInteractable)
                    {
                        _firstFocusedInteractable = null;
                    }
                }
                else
                {
                    _currPinchState           = PinchState.None;
                    _firstFocusedInteractable = null;
                }
                break;

            case PinchState.PinchStay:
                if (!isPinching)
                {
                    _currPinchState = PinchState.PinchUp;
                }
                // if object is not focused anymore, then forget it
                if (currFocusedInteractable != _firstFocusedInteractable)
                {
                    _firstFocusedInteractable = null;
                }
                break;

            // pinch down lasts for a max of 1 frame. either go to pinch stay or up
            case PinchState.PinchDown:
                _currPinchState = isPinching ? PinchState.PinchStay : PinchState.PinchUp;
                // if the focused interactable changes, then the original one is now invalid
                if (_firstFocusedInteractable != currFocusedInteractable)
                {
                    _firstFocusedInteractable = null;
                }
                break;

            default:
                if (isPinching)
                {
                    _currPinchState = PinchState.PinchDown;
                    // this is the interactable that must be focused through out the pinch up and down
                    // gesture.
                    _firstFocusedInteractable = currFocusedInteractable;
                }
                break;
            }
        }
        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;
        }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        //_y.text = throwhigh.ToString();
        _catch_Right = _ovrHand_right.GetFingerPinchStrength(OVRHand.HandFinger.Middle) >= 0.1f && _ovrHand_right.GetFingerPinchStrength(OVRHand.HandFinger.Index) >= 0.05f && _ovrHand_right.GetFingerPinchStrength(OVRHand.HandFinger.Thumb) >= 0.05f;
        _catch_Left  = _ovrHand_left.GetFingerPinchStrength(OVRHand.HandFinger.Middle) >= 0.1f && _ovrHand_left.GetFingerPinchStrength(OVRHand.HandFinger.Index) >= 0.05f && _ovrHand_left.GetFingerPinchStrength(OVRHand.HandFinger.Thumb) >= 0.05f;
        touchSphere();
        if ((_catch_Right && _hold_Right) || (_catch_Left && _hold_Left))
        {
            if (released)
            {
                released = false;
                CatchSphere();
            }
        }
        else
        {
            if (!released)
            {
                ReleaseSphere();
                released = true;
            }
        }

        /*if (_catch_Left)
         * {
         *  _gu2.SetActive(true);
         *  _pa2.SetActive(false);
         * }
         * else
         * {
         *  _gu2.SetActive(false);
         *  _pa2.SetActive(true);
         * }
         *
         * if (_catch_Right)
         * {
         *
         *  _gu.SetActive(true);
         *  _pa.SetActive(false);
         * }
         * else
         * {
         *  _gu.SetActive(false);
         *  _pa.SetActive(true);
         * }
         * if (released)
         * {
         *  _release.text = "release";
         * }
         * else
         * {
         *  _release.text = "hold";
         * }*/
    }
Example #8
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 #9
0
    void DetectPinch()
    {
        float currPinch = hand.GetFingerPinchStrength(OVRHand.HandFinger.Index);

        if (!m_grabbedObj && currPinch > Config.PINCH_THRESHOLD)
        {
            GrabBegin();
        }
        else if (m_grabbedObj && currPinch < Config.PINCH_THRESHOLD)
        {
            GrabEnd();
        }
    }
Example #10
0
    private void CheckIndexPinch()
    {
        float pinchStrength = m_hand.GetFingerPinchStrength(OVRHand.HandFinger.Index);

        if (!m_grabbedObj && pinchStrength > pinchTreshold && m_grabCandidates.Count > 0)
        {
            GrabBegin();
        }
        else if (m_grabbedObj && (pinchStrength > pinchTreshold))
        {
            GrabEnd();
        }
    }
        /// <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);
        }
        /// <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);
        }
Example #13
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));
     }
 }
Example #14
0
    // Update is called once per frame
    void Update()
    {
        if (!b_hasInitialized)
        {
            return;
        }

        for (int i = 0; i < i_numBones; i++)
        {
            t_debugs[i].position = t_targets[i].position;
        }

        f_pinchStrengths[0] = hand.GetFingerPinchStrength(OVRHand.HandFinger.Thumb);
        f_pinchStrengths[1] = hand.GetFingerPinchStrength(OVRHand.HandFinger.Index);
        f_pinchStrengths[2] = hand.GetFingerPinchStrength(OVRHand.HandFinger.Middle);
        f_pinchStrengths[3] = hand.GetFingerPinchStrength(OVRHand.HandFinger.Ring);
        f_pinchStrengths[4] = hand.GetFingerPinchStrength(OVRHand.HandFinger.Pinky);

        tmp_amounts[0].text = i_numBones.ToString();

        //hand.HandState.
        //Vector3 rot = Quaternion.ToEulerAngles(hand.HandState.);

        //tmp_amounts[0].text = i_numBones.ToString();
        //tmp_amounts[1].text = hand.IsPointerPoseValid.ToString();

        //for(int i=0;i<5;i++)
        //{
        //    tmp_amounts[i].text = finger.ToString() + " %";
        //}

        //tmp_amounts[0].text = (fingers.extentThumb * 1).ToString() + " %";
        //tmp_amounts[1].text = (fingers.extentIndex * 1).ToString() + " %";
        //tmp_amounts[2].text = (fingers.extentMiddle * 1).ToString() + " %";
        //tmp_amounts[3].text = (fingers.extentRing * 1).ToString() + " %";
        //tmp_amounts[4].text = (fingers.extentPinky * 1).ToString() + " %";
    }
    private void CheckIndexPinch()
    {
        //float pinchStrength = hand.GetFingerPinchStrength(OVRHand.HandFinger.Index);
        float pinchStrength = hand.GetFingerPinchStrength(OVRHand.HandFinger.Middle);       // Trigger grab when middle finger is pinched
        bool  isPinching    = pinchStrength > pinchThreshold;

        if (!m_grabbedObj && isPinching && m_grabCandidates.Count > 0)
        {
            GrabBegin();
        }
        else if (m_grabbedObj && !isPinching)
        {
            GrabEnd();
        }
    }
Example #16
0
    /// <summary>
    /// Invoked by OVRCameraRig's UpdatedAnchors callback. Allows the Hmd rotation to update the facing direction of the player.
    /// </summary>
    public void UpdateTransform(OVRCameraRig rig)
    {
        //GET INPUT FIRST TO HAVE BLUETOOTH DATA
        if (handMovement)
        {
            Vector3 handDelta = transform.position - rightHand.transform.position;
            handDelta.y = handDelta.z;
            Vector2 pinchAxis = (Vector2)handDelta.normalized * rightHand.GetFingerPinchStrength(OVRHand.HandFinger.Middle);

            primaryInputAxis = pinchAxis;
        }
        else
        {
            primaryInputAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.Gamepad);

            if (primaryInputAxis.x == 0 || !Mathf.Approximately(primaryInputAxis.magnitude, primaryInputAxisPrevious.magnitude))
            {
                updateMoveDirection = true;
            }
            else
            {
                updateMoveDirection = false;
            }

            primaryInputAxisPrevious = primaryInputAxis;
        }

        Transform root      = CameraRig.trackingSpace;
        Transform centerEye = CameraRig.centerEyeAnchor;

        if (HmdRotatesY && updateMoveDirection && !handMovement && !Teleported)
        {
            Vector3    prevPos = root.position;
            Quaternion prevRot = root.rotation;

            transform.rotation = Quaternion.Euler(0.0f, centerEye.rotation.eulerAngles.y, 0.0f);

            root.position = prevPos;
            root.rotation = prevRot;
        }

        UpdateController();
        if (TransformUpdated != null)
        {
            TransformUpdated(root);
        }
    }
Example #17
0
        public void UpdateState(OVRHand hand, bool _displayLog)
        {
            float pinchStrength = hand.GetFingerPinchStrength(OVRHand.HandFinger.Index);
            bool  isPinching    = Mathf.Abs(PINCH_STRENGTH_THRESHOLD - pinchStrength) < Mathf.Epsilon;
            var   oldPinchState = _currPinchState;

            // if (_displayLog) UIEventController.Instance.DelayUIEvent(ScreenDebugLogView.EVENT_SCREEN_DEBUGLOG_NEW_TEXT, 3, true, "old[" + oldPinchState.ToString() + "]::strength[" + pinchStrength + "]::isPinching[" + isPinching + "]::IsDataValid[" + hand.IsDataValid + "]");

            switch (oldPinchState)
            {
            case MyPinchState.PinchUp:
                // can only be in pinch up for a single frame, so consider
                // next frame carefully
                if (isPinching)
                {
                    _currPinchState = MyPinchState.PinchDown;
                }
                else
                {
                    _currPinchState = MyPinchState.None;
                }
                break;

            case MyPinchState.PinchStay:
                if (!isPinching)
                {
                    _currPinchState = MyPinchState.PinchUp;
                }
                break;

            // pinch down lasts for a max of 1 frame. either go to pinch stay or up
            case MyPinchState.PinchDown:
                _currPinchState = isPinching ? MyPinchState.PinchStay : MyPinchState.PinchUp;
                break;

            default:
                if (isPinching)
                {
                    _currPinchState = MyPinchState.PinchDown;
                    // this is the interactable that must be focused through out the pinch up and down
                    // gesture.
                }
                break;
            }
        }
    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 #19
0
    // Update is called once per frame
    void Update()
    {
        if (_OVRGrabbable.isGrabbed)
        {
            // Show and update laser beam
            //if (OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger) || (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger)))
            if (_Hand.GetFingerPinchStrength(OVRHand.HandFinger.Index) > 0.3f || OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger) || (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger)))      // Trigger laser beam when index finger is pinched or controller trigger is pressed
            {
                // Turn on laser
                if (!laserBeam.activeSelf)
                {
                    _LaserOn = true;
                    ActivateLaserBeam(_LaserOn);
                }

                // Shoot RayCast and check if hit object (only applies to valid Layer)
                if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out RaycastHit hit, Mathf.Infinity, validLaserHitLayer))
                {
                    // Position and scale the laser
                    laserBeam.transform.position   = Vector3.Lerp(transform.position, hit.point, 0.5f);
                    laserBeam.transform.localScale = new Vector3(laserBeam.transform.localScale.x, laserBeam.transform.localScale.y, hit.distance);

                    // Position and show the laser hit point
                    laserHitPoint.transform.position = hit.point;
                    laserHitPoint.SetActive(true);
                }
                else
                {
                    laserHitPoint.SetActive(false);
                    laserBeam.transform.localScale    = _LaserLength;
                    laserBeam.transform.localPosition = Vector3.zero;
                    laserBeam.transform.Translate(Vector3.forward * LASER_CENTRE_POINT);
                }
            }
            else
            {
                // Turn off beam when trigger button is released
                if (laserBeam.activeSelf)
                {
                    DeactivateLaser();
                }
            }
        }
Example #20
0
        private void Update()
        {
            //入力なし
            _inputData.InputState = HpInputState.NoInput;

            //指定した手のした座標を構造体にぶち込む
            _inputData.InputPosition = _ovrSkeleton.Bones[(int)_boneId].Transform.position;
            Debug.Log(_inputData.InputPosition);

            //PinchPoseできてるかどうか
            float currentPinchStrength = _ovrHand.GetFingerPinchStrength(_handFingerType);
            bool  isPinching           = _ovrHand.GetFingerIsPinching(_handFingerType);
            bool  isPinchPose          = isPinching && currentPinchStrength >= _minPinchStrengthValue;

            //入力中
            if (isPinchPose && _isInput)
            {
                Debug.Log("入力中");
                _isInput = true;
                _inputData.InputState = HpInputState.Input;
            }

            //入力した瞬間
            if (isPinchPose && _isInput == false)
            {
                Debug.Log("入力した瞬間");
                _isInput = true;
                _inputData.InputState = HpInputState.InputDown;
            }

            //ピンチポーズしてない
            if (isPinchPose == false)
            {
                _isInput = false;
            }

            //構造体をのせてメッセージを発行
            _inputDataSubject.OnNext(_inputData);
        }
 void AlignWithHand(OVRHand hand, OVRSkeleton skeleton)
 {
     if (pinching)
     {
         if (hand.GetFingerPinchStrength(OVRHand.HandFinger.Index) < 0.8f)
         {
             pinching = false;
         }
     }
     else
     {
         if (hand.GetFingerIsPinching(OVRHand.HandFinger.Index))
         {
             if (GetComponent <Flashlight>())
             {
                 GetComponent <Flashlight>().ToggleFlashlight();
             }
             pinching = true;
         }
     }
     flashlightRoot.position = skeleton.Bones[6].Transform.position;
     flashlightRoot.rotation = Quaternion.LookRotation(skeleton.Bones[6].Transform.position - skeleton.Bones[0].Transform.position);
 }
    public bool IsPinchingWithRange(TherapyData.PinchType type, float threshold)
    {
        switch (type)
        {
        case TherapyData.PinchType.Pad2:
            return(m_is2PadPinch && m_Hand.GetFingerPinchStrength(OVRHand.HandFinger.Index) >= threshold);

        case TherapyData.PinchType.Pad3:
            return(m_is3PadPinch && m_Hand.GetFingerPinchStrength(OVRHand.HandFinger.Index) >= threshold);

        case TherapyData.PinchType.Tip2:
            return(m_is2TipPinch && m_Hand.GetFingerPinchStrength(OVRHand.HandFinger.Index) >= threshold);

        case TherapyData.PinchType.Tip3:
            return(m_is3TipPinch && m_Hand.GetFingerPinchStrength(OVRHand.HandFinger.Index) >= threshold);
        }
        return(false);
    }
Example #23
0
        void HandleInteractionAction(XRNode node, InputHelpers.Button button, ref InteractionState interactionState)
        {
            bool pressed = false;
            //inputDevice.IsPressed(button, out pressed, m_AxisToPressThreshold);
            float indexPinch = ovrHand.GetFingerPinchStrength(OVRHand.HandFinger.Index);

            pressed = indexPinch > 0.9f;
            if (pressed)
            {
                if (!interactionState.active)
                {
                    interactionState.activatedThisFrame = true;
                    interactionState.active             = true;
                }
            }
            else
            {
                if (interactionState.active)
                {
                    interactionState.deActivatedThisFrame = true;
                    interactionState.active = false;
                }
            }
        }
Example #24
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 #25
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);
        }
Example #26
0
 static private bool IsFingerPinched(OVRHand hand, OVRHand.HandFinger finger)
 {
     return(hand.GetFingerConfidence(finger) == OVRHand.TrackingConfidence.High && hand.GetFingerIsPinching(finger) && hand.GetFingerPinchStrength(finger) >= PinchMaxStrength);
 }
    void CheckPinch()
    {
        List <OVRBoneCapsule> capsules  = ske._capsules;
        List <float>          distances = new List <float>();

        //Set default pinch strength
        float index  = hand.GetFingerPinchStrength(OVRHand.HandFinger.Index);
        float middle = hand.GetFingerPinchStrength(OVRHand.HandFinger.Middle);
        float ring   = hand.GetFingerPinchStrength(OVRHand.HandFinger.Ring);
        float pinky  = hand.GetFingerPinchStrength(OVRHand.HandFinger.Pinky);

        bool isIndex  = index > treshold;
        bool isMiddle = middle > treshold;
        bool isRing   = ring > treshold;
        bool isPinky  = pinky > treshold;


        foreach (var capsule in capsules)
        {
            // Bit shift the index of the layer (8) to get a bit mask
            int layerMask = 1 << 8;

            // This would cast rays only against colliders in layer 8.
            // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
            layerMask = ~layerMask;

            RaycastHit hit;
            // Does the ray intersect any objects excluding the player layer
            if (Physics.Raycast(capsule.CapsuleCollider.transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
            {
                distances.Add(hit.distance);
                if (hit.distance <= 0.01f)
                {
                    //Freeze index
                    if (capsule == capsules [7] || capsule == capsules[8] || capsule == capsules[9])
                    {
                        isIndex = true;
                    }
                    //Freeze middle
                    if (capsule == capsules[10] || capsule == capsules[11] || capsule == capsules[12])
                    {
                        isMiddle = true;
                    }
                    //Freeze ring
                    if (capsule == capsules[13] || capsule == capsules[14] || capsule == capsules[15])
                    {
                        isMiddle = true;
                    }
                }
            }
        }



        if (!m_grabbedObj && (isIndex || isMiddle || isRing) && m_grabCandidates.Count > 0)
        {
            GrabBegin();
            //Set the frozen finger
            if (isAdjustedHandGrip)
            {
                ske.FreezeIndex = true;
                if (isMiddle)
                {
                    ske.FreezeMiddle = true;
                }
                //else
                //{
                //    ske.FreezeMiddle = false;
                //}

                if (isRing)
                {
                    ske.FreezeRing = true;
                }
                //else
                //{
                //    ske.FreezeRing = false;
                //}

                if (isPinky)
                {
                    ske.FreezePinky = true;
                }
                //else
                //{
                //    ske.FreezePinky = false;
                //}
            }
        }

        else if (m_grabbedObj && !(isIndex || isMiddle || isRing))
        {
            GrabEnd();
            ske.FreezeIndex  = false;
            ske.FreezeMiddle = false;
            ske.FreezeRing   = false;
            ske.FreezePinky  = false;
        }
    }
Example #28
0
 public float GetFingerStrength(FingerType fingerType)
 {
     OVRHand.HandFinger finger = ConvertFingerType(fingerType);
     return(_hand.GetFingerPinchStrength(finger));
 }