Esempio n. 1
0
    private bool ThumbDetected()
    {
        //※メモ 親指は他の指と異なり特殊でまっすぐ伸びているか?の判定+親指の向きで判定する。
        var jointedHand = HandJointUtils.FindHand(handType);

        //Get TargetHamd
        if (jointedHand.TryGetJoint(TrackedHandJoint.Palm, out MixedRealityPose PalmPose))
        {
            MixedRealityPose ThumbTipPose, ThumbDistalPose, ThumbProximalPose;
            //Get finger Joint Deta
            if (jointedHand.TryGetJoint(TrackedHandJoint.ThumbTip, out ThumbTipPose) &&
                jointedHand.TryGetJoint(TrackedHandJoint.ThumbDistalJoint, out ThumbDistalPose) &&
                jointedHand.TryGetJoint(TrackedHandJoint.ThumbProximalJoint, out ThumbProximalPose))
            {
                Vector3 finger1 = ThumbProximalPose.Position - PalmPose.Position;
                Vector3 finger2 = ThumbDistalPose.Position - ThumbProximalPose.Position;
                Vector3 finger3 = ThumbTipPose.Position - ThumbProximalPose.Position;

                float c   = Vector3.Angle(PalmPose.Position, finger1);
                float d   = Vector3.Angle(finger1, finger2);
                float e   = Vector3.Angle(finger2, finger3);
                float aba = (Mathf.Abs(d) + Mathf.Abs(e) / 2);

                text.text = aba.ToString();
                if (aba < thumbThreshold)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 2
0
    private bool middlefingerDetected()
    {
        var jointedHand = HandJointUtils.FindHand(handType);

        if (jointedHand.TryGetJoint(TrackedHandJoint.Palm, out MixedRealityPose PalmPose))
        {
            MixedRealityPose middleTipsPose, middleDistalPose, middleKnucklePose, middleMiddlePose;
            if (jointedHand.TryGetJoint(TrackedHandJoint.MiddleTip, out middleTipsPose) &&
                jointedHand.TryGetJoint(TrackedHandJoint.MiddleDistalJoint, out middleDistalPose) &&
                jointedHand.TryGetJoint(TrackedHandJoint.MiddleKnuckle, out middleKnucklePose) && jointedHand.TryGetJoint(TrackedHandJoint.MiddleMiddleJoint, out middleMiddlePose))
            {
                Vector3 finger1 = middleKnucklePose.Position - PalmPose.Position;
                Vector3 finger2 = middleMiddlePose.Position - middleKnucklePose.Position;
                Vector3 finger3 = middleDistalPose.Position - middleMiddlePose.Position;
                Vector3 finger4 = middleTipsPose.Position - middleDistalPose.Position;

                float c = Vector3.Angle(PalmPose.Position, finger1);
                float d = Vector3.Angle(finger1, finger2);
                float e = Vector3.Angle(finger2, finger3);
                float f = Vector3.Angle(finger3, finger4);

                float aba = (Mathf.Abs(d) + Mathf.Abs(e) + Mathf.Abs(f)) / 3;
                if (aba < middleThreshold)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 3
0
    private bool indexfingerDetected()
    {
        var jointedHand = HandJointUtils.FindHand(handType);

        if (jointedHand.TryGetJoint(TrackedHandJoint.Palm, out MixedRealityPose PalmPose))
        {
            //各関節のpose
            MixedRealityPose indexTipPose, indexDistalPose, IndexKnucklePose, indexMiddlePose;
            if (jointedHand.TryGetJoint(TrackedHandJoint.IndexTip, out indexTipPose) && jointedHand.TryGetJoint(TrackedHandJoint.IndexDistalJoint, out indexDistalPose) && jointedHand.TryGetJoint(TrackedHandJoint.IndexMiddleJoint, out indexMiddlePose) && jointedHand.TryGetJoint(TrackedHandJoint.IndexKnuckle, out IndexKnucklePose))
            {
                Vector3 finger1 = IndexKnucklePose.Position - PalmPose.Position;
                Vector3 finger2 = indexMiddlePose.Position - IndexKnucklePose.Position;
                Vector3 finger3 = indexDistalPose.Position - indexMiddlePose.Position;
                Vector3 finger4 = indexTipPose.Position - indexDistalPose.Position;

                float c = Vector3.Angle(PalmPose.Position, finger1);
                float d = Vector3.Angle(finger1, finger2);
                float e = Vector3.Angle(finger2, finger3);
                float f = Vector3.Angle(finger3, finger4);

                float aba = (Mathf.Abs(d) + Mathf.Abs(e) + Mathf.Abs(f)) / 3;

                if (aba < indexThreshold)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Esempio n. 4
0
 public void Update()
 {
     if (HandJointUtils.TryGetJointPose(TrackedHandJoint.Wrist, Handedness.Any, out MixedRealityPose pose))
     {
         Vector3           positionOfWrist = pose.Position;
         IMixedRealityHand whichHand       = HandJointUtils.FindHand(Handedness.Any);
     }
 }
Esempio n. 5
0
    private bool HanddirDetected()
    {
        var jointedHand = HandJointUtils.FindHand(handType);

        if (jointedHand.TryGetJoint(TrackedHandJoint.Palm, out MixedRealityPose palmPose))
        {
            if (facingThreshold < Vector3.Angle(palmPose.Up, CameraCache.Main.transform.forward))
            {
//                Debug.Log(palmPose.Up);
                return(true);
            }
        }

        return(false);
    }
Esempio n. 6
0
    public GameObject[] GetHandsToRecord()
    {
        GameObject[] hands = new GameObject[2];

        if (HandJointUtils.FindHand(Handedness.Left) != null)
        {
            hands[0] = HandJointUtils.FindHand(Handedness.Left).Visualizer.GameObjectProxy;
        }

        if (HandJointUtils.FindHand(Handedness.Right) != null)
        {
            hands[1] = HandJointUtils.FindHand(Handedness.Right).Visualizer.GameObjectProxy;
        }

        return(hands);
    }
Esempio n. 7
0
        // Start is called before the first frame update
        void Awake()
        {
            RPCRuntimeUPDShortcut = UtilityExtentions.GetRPCShortcut("RPCRuntimeReceiveData");

            if (RootTransform.root != null)
            {
                transform.SetParent(RootTransform.root.transform);
            }

            var tmp = (TrackedHandJoint[])System.Enum.GetValues(typeof(TrackedHandJoint));

            _jointNameListArray = new TrackedHandJoint[tmp.Length - 2];
            for (int i = 0, j = 0; i < tmp.Length; i++)
            {
                if ((i != (int)TrackedHandJoint.None) && (i != (int)TrackedHandJoint.Palm))
                {
                    _jointNameListArray[j++] = tmp[i];
                }
            }

            _mixedRealityHand       = HandJointUtils.FindHand(Hand);
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;

            // init the fade state
            setMeshEnabled(false);
            // force to hide the mesh at the start
            _handStateFading.SetState(HandStateFading.FadeState.Hide);

            Debug.Assert(localTargetFPS != 0);
            Debug.Assert(clientTargetFPS != 0);

            localUpdateFrameRate  = (int)(systemFPS / (float)localTargetFPS);
            clientSendFrameRate   = (int)(systemFPS / (float)clientTargetFPS);
            clientUpdateFrameRate = (int)(systemFPS / (float)lerpTargetFPS);

            if (localUpdateFrameRate == 0 || clientSendFrameRate == 0 || clientUpdateFrameRate == 0)
            {
                //prevent divide by zero on the modulus divs below
                Debug.Log("FATAL Div by Zero! Local: " + localUpdateFrameRate.ToString() + " Send: " + clientSendFrameRate.ToString() + " Client: " + clientUpdateFrameRate.ToString());
            }
        }
Esempio n. 8
0
    private bool RingAndPinkyFingerDetected()
    {
        //※メモ HoloLens2の場合実装的には薬指、小指それぞれの判定は可能だが、実機の場合特に小指単体のトラッキング精度に問題があるため薬指、小指はひとまとめで一つの指として検知する。
        var jointedHand = HandJointUtils.FindHand(handType);

        if (jointedHand.TryGetJoint(TrackedHandJoint.Palm, out MixedRealityPose PalmPose))
        {
            MixedRealityPose PinkyTipPose,
                             PinkyDistalPose,
                             PinkyMiddlePose,
                             PinkyKnucklePose,
                             RingTipPose,
                             RingDistalPose,
                             RingMiddlePose,
                             RingKnucklePose;
            if (jointedHand.TryGetJoint(TrackedHandJoint.RingTip, out RingTipPose) && jointedHand.TryGetJoint(TrackedHandJoint.RingMiddleJoint, out RingMiddlePose) && jointedHand.TryGetJoint(TrackedHandJoint.RingDistalJoint, out RingDistalPose) &&
                jointedHand.TryGetJoint(TrackedHandJoint.RingKnuckle, out RingKnucklePose))
            {
                Vector3 finger1 = RingKnucklePose.Position - PalmPose.Position;
                Vector3 finger2 = RingMiddlePose.Position - RingKnucklePose.Position;
                Vector3 finger3 = RingDistalPose.Position - RingMiddlePose.Position;
                Vector3 finger4 = RingTipPose.Position - RingDistalPose.Position;

                float c   = Vector3.Angle(PalmPose.Position, finger1);
                float d   = Vector3.Angle(finger1, finger2);
                float e   = Vector3.Angle(finger2, finger3);
                float f   = Vector3.Angle(finger3, finger4);
                float aba = (Mathf.Abs(d) + Mathf.Abs(e) + Mathf.Abs(f)) / 3;
                Debug.Log(aba);
                if (aba < ringAndPinkyFingerThreshpld)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
        private IEnumerator TestTouchableDistances(BaseNearInteractionTouchable touchable, float colliderThickness, GameObject objectDownExpected)
        {
            Handedness handedness = Handedness.Right;

            ArticulatedHandPose.GestureId gesture = ArticulatedHandPose.GestureId.Open;

            yield return(PlayModeTestUtilities.ShowHand(handedness, inputSim));

            PokePointer       pokePointer = null;
            IMixedRealityHand hand        = HandJointUtils.FindHand(handedness);

            Assert.IsNotNull(hand);
            foreach (IMixedRealityPointer pointer in hand.InputSource.Pointers)
            {
                pokePointer = pointer as PokePointer;
                if (pokePointer)
                {
                    break;
                }
            }
            Assert.IsNotNull(pokePointer);
            float touchableDistance = pokePointer.TouchableDistance;

            float debounceThreshold = 0.01f;

            touchable.DebounceThreshold = debounceThreshold;

            Vector3 center = touchable.transform.position;

            float   margin    = 0.001f;
            Vector3 pStart    = center + new Vector3(0, 0, -touchableDistance - 0.5f);
            Vector3 pTouch    = center + new Vector3(0, 0, -touchableDistance + margin);
            Vector3 pPoke     = center + new Vector3(0, 0, -colliderThickness + margin);
            Vector3 pDebounce = center + new Vector3(0, 0, -colliderThickness - touchable.DebounceThreshold - margin);
            Vector3 pEnd      = center + new Vector3(0, 0, touchableDistance + 0.5f);

            // Test return beyond DebounceThreshold
            yield return(PlayModeTestUtilities.MoveHand(pStart, pStart, gesture, handedness, inputSim, 1));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pStart, pTouch, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pTouch, pPoke, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.AreEqual(objectDownExpected, pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pPoke, pDebounce, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pDebounce, pStart, gesture, handedness, inputSim));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            // Test touchable distance behind the surface
            yield return(PlayModeTestUtilities.MoveHand(pStart, pStart, gesture, handedness, inputSim, 1));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pStart, pTouch, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pTouch, pPoke, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.AreEqual(objectDownExpected, pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pPoke, pEnd, gesture, handedness, inputSim));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pEnd, pDebounce, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pDebounce, pStart, gesture, handedness, inputSim));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.HideHand(handedness, inputSim));
        }
Esempio n. 10
0
        void Update()
        {
            if (!photonView.IsMine)
            {
                if (_isShow)
                {
                    if (((clientCounterFrames % clientUpdateFrameRate) == 0))
                    {
                        //now the wrist. lerp motion and rotation
                        GameObject wrist    = GetJointObject(TrackedHandJoint.Wrist);
                        float      lerpTime = Mathf.Clamp(InterpolatePointLerpSpeed * Time.smoothDeltaTime, 0.33f, 1.0f);
                        wrist.transform.localPosition = Vector3.Lerp(wrist.transform.localPosition, _rootPos, lerpTime);
                        Vector3 rotV = wrist.transform.localEulerAngles;
                        wrist.transform.localEulerAngles = Vector3.Lerp(rotV, _rootRot.Normalise(rotV - new Vector3(180, 180, 180), rotV + new Vector3(180, 180, 180)), lerpTime);

                        GameObject objectJoint;
                        float      x, y, z, w;
                        for (int key = 0; key < _jointNameListArray.Length; key++)
                        {
                            int index = (int)_jointNameListArray[key];
                            if (index >= 0 && index < jointObjects.Length)
                            {
                                if (index == (int)TrackedHandJoint.Wrist)
                                {
                                    continue;
                                }
                                objectJoint = jointObjects[index];
                                if (objectJoint != null)
                                {
                                    int rIdx = (int)index * 4;
                                    x = (float)ShortToFloat(_rotArrayShorts[rIdx + 0]);
                                    y = (float)ShortToFloat(_rotArrayShorts[rIdx + 1]);
                                    z = (float)ShortToFloat(_rotArrayShorts[rIdx + 2]);
                                    w = (float)ShortToFloat(_rotArrayShorts[rIdx + 3]);
                                    //lerp
                                    if (x == 0 && y == 0 && z == 0 && w == 0)
                                    {
                                        //zero quaternions are invalid
                                        //Debug.Log("Zero Quat: x==0&&y==0&&z==0&&w==0");
                                        continue;
                                    }

                                    Quaternion rotQ = objectJoint.transform.localRotation;
                                    objectJoint.transform.localRotation = Quaternion.Lerp(rotQ, new Quaternion(x, y, z, w).normalized, lerpTime);
                                }
                            }
                        }
                        clientCounterFrames = 0;
                    }
                    ++clientCounterFrames;
                }
            }
            else
            {
                bool isHandExist = HandJointUtils.TryGetJointPose(TrackedHandJoint.Wrist, Hand, out MixedRealityPose pose);
                if (isHandExist)
                {
                    if (_mixedRealityHand == null)
                    {
                        _mixedRealityHand = HandJointUtils.FindHand(Hand);
                    }
                    if (((localCounterFrames % localUpdateFrameRate) == 0))
                    {
                        SetJoint(TrackedHandJoint.Wrist, true);
                        // Enable the mesh if its disabled
                        if (!_isShow)
                        {
                            photonView.RPC("setMeshEnabled", RpcTarget.All, true);
                        }
                        // Set each of the joints
                        int count = _jointNameListArray.Length;
                        for (int i = 0; i < count; i++)
                        {
                            if (_jointNameListArray[i] != TrackedHandJoint.Wrist)
                            {
                                SetJoint(_jointNameListArray[i], false);
                            }
                        }
                    }
                    if ((localCounterFrames % clientSendFrameRate) == 0)
                    {
                        // Send the client local joints
                        GameObject wrist = GetJointObject(TrackedHandJoint.Wrist);
                        photonView.SendToAllUnReliableRPC(RPCRuntimeUPDShortcut, ReceiverGroup.Others, wrist.transform.localPosition, wrist.transform.localRotation, _rotArrayShorts);
                        localCounterFrames = 0;
                    }
                }
                else if (!isHandExist)
                {
                    // Disable the mesh if the Hand Wrist doesn't exist
                    _mixedRealityHand = null;
                    if (_isShow)
                    {
                        photonView.RPC("setMeshEnabled", RpcTarget.All, false);
                    }
                }
                //always run the counter so its ready to send on first frame when the hand exists
                ++localCounterFrames;
            }
        }
 /// <summary>
 /// Return true if either of the user's hands are being tracked.
 /// Return false if neither of the user's hands are being tracked.
 /// </summary>
 private bool IsHandTracked()
 {
     return(HandJointUtils.FindHand(Handedness.Right) != null || HandJointUtils.FindHand(Handedness.Left) != null);
 }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        handdetected = HandJointUtils.FindHand(handType)?.TryGetJoint(TrackedHandJoint.Palm, out MixedRealityPose PalmPose);
        if (handdetected != null && handdetected == true)
        {
            if (ThumbDetected() && HanddirDetected())
            {
                OnThumbFingerDetect.Invoke();
            }
            else
            {
                OnThumbFingerLost.Invoke();
            }
            if (indexfingerDetected() && HanddirDetected())
            {
                Debug.Log("index:Open");
                OnIndexFingerDetect.Invoke();
                if (indexFirstfinger)
                {
                    indexFirstfinger = false;
                    //indexFirstlostfinger = true;
                    OnIndexFingerFirst.Invoke();
                }
            }
            else
            {
                Debug.Log("index:Close");
                OnIndexFingerLost.Invoke();
                if (!indexFirstfinger)
                {
                    indexFirstfinger = true;
                    //indexFirstlostfinger = false;
                    OnIndexLostFirst.Invoke();
                }
            }


            if (middlefingerDetected() && HanddirDetected())
            {
                Debug.Log("middle:Open");
                OnMiddleFingerDetect.Invoke();
                if (middleFirstfinger)
                {
                    middleFirstfinger = false;
                    //middleFirstLostfinger = true;
                    OnMiddleFingerFirst.Invoke();
                }
            }
            else
            {
                Debug.Log("middle:Close");
                OnMiddleFingerLost.Invoke();
                if (!middleFirstfinger)
                {
                    middleFirstfinger = true;
                    // middleFirstLostfinger = false;
                    OnMiddleLostFirst.Invoke();
                }
            }

            if (RingAndPinkyFingerDetected() && HanddirDetected())
            {
                Debug.Log("RingAndPinky:Open");
                OnRingAndPinkyDetect.Invoke();
                if (ringandPinkyFirstfinger)
                {
                    ringandPinkyFirstfinger = false;
                    //ringandPinkyFirstLostfinger = true;
                    OnRingAndPinkyFingerFirst.Invoke();
                }
            }
            else
            {
                Debug.Log("RingAndPinky:Close");
                OnRingAndPinkyLost.Invoke();
                if (!ringandPinkyFirstfinger)
                {
                    ringandPinkyFirstfinger = true;
                    //ringandPinkyFirstLostfinger = false;
                    OnRingAndPinkyLostFirst.Invoke();
                }
            }
        }
        else
        {
            OnHandLostEvent.Invoke();
        }
    }