Пример #1
0
        private void Process(object sender, System.Timers.ElapsedEventArgs e)
        {
            Frame frame = new Frame(_controller.Frame());

            _mdManager.Detect(frame);
            _timer.Start();
        }
        private void QueryFrame()
        {
            long id = long.MinValue;

            while (_isRunning)
            {
                Leap.Frame f = _controller.Frame();
                if (f.Id == id)
                {
                    continue;
                }
                _frameBuffer.Add(new Frame(f));
                Detect();
                id = f.Id;
            }
            try
            {
            }
            catch (Exception ex)
            {
                if (OnException != null)
                {
                    OnException(ex);
                }
                else
                {
                    throw ex;
                }
            }
        }
Пример #3
0
        private void button_catch_Click(object sender, EventArgs e)
        {
            Frame frame = new Frame(_c.Frame());

            foreach (Hand hand in frame.Hands)
            {
                HandFeatures hf = HandFeatures.ExtractFeatures(hand);
                Console.WriteLine("state code = " + hf.StateCode + "," + Convert.ToString(hf.StateCode, 2));
            }
        }
Пример #4
0
        public void DoPulse()
        {
            if (m_controller.IsConnected)
            {
                bool l_leftFound  = false;
                bool l_rightFound = false;

                Leap.Frame l_frame = m_controller.Frame();
                if (l_frame != null)
                {
                    foreach (Leap.Hand l_hand in l_frame.Hands)
                    {
                        if (l_hand.IsLeft && !l_leftFound)
                        {
                            l_leftFound = true;
                            foreach (Leap.Finger l_finger in l_hand.Fingers)
                            {
                                if (l_finger.Type == Leap.Finger.FingerType.TYPE_INDEX)
                                {
                                    l_finger.TipPosition.Convert(ref m_leftTipPosition);
                                    ConvertOrientation(ref m_leftTipPosition);
                                    break;
                                }
                            }
                            continue;
                        }
                        if (l_hand.IsRight && !l_rightFound)
                        {
                            l_rightFound = true;
                            foreach (Leap.Finger l_finger in l_hand.Fingers)
                            {
                                if (l_finger.Type == Leap.Finger.FingerType.TYPE_INDEX)
                                {
                                    l_finger.TipPosition.Convert(ref m_rightTipPosition);
                                    ConvertOrientation(ref m_rightTipPosition);
                                    break;
                                }
                            }
                        }
                    }
                }

                m_core.GetControlManager().SetHandPresence(ControlManager.Hand.Left, l_rightFound, l_rightFound ? m_rightTipPosition : ms_zeroPoint);
                m_core.GetControlManager().SetHandPresence(ControlManager.Hand.Right, l_leftFound, l_leftFound ? m_leftTipPosition : ms_zeroPoint);
            }
        }
Пример #5
0
 public void Next()
 {
     if (_mode == Mode.Live)
     {
         SetCurrentFrame(new Frame(_controller.Frame()));
     }
     else if (_mode == Mode.Clip)
     {
         if (_clipFrames == null)
         {
             return;
         }
         _clipFrameIndex++;
         if (_clipFrameIndex >= _clipFrames.Count)
         {
             _clipFrameIndex = _clipFrames.Count - 1;
         }
         SetCurrentFrame(_clipFrames[_clipFrameIndex]);
     }
     if (_isRecording)
     {
         _recordFrames.Add(_currentFrame);
     }
 }
Пример #6
0
 public void connectToHands()
 {
     if (controller.Frame().Hands.Count == 1)
     {
         Leap.Hand temp = controller.Frame().Hands[0];
         if (temp.IsLeft)
         {
             lefthand  = temp;
             righthand = null;
         }
         else
         {
             righthand = temp;
             lefthand  = null;
         }
     }
     else if (controller.Frame().Hands.Count == 2)
     {
         Leap.Hand temp = controller.Frame().Hands[0];
         if (temp.IsLeft)
         {
             lefthand  = temp;
             righthand = controller.Frame().Hands[1];
         }
         else
         {
             righthand = temp;
             lefthand  = controller.Frame().Hands[1];
         }
     }
     else
     {
         lefthand  = null;
         righthand = null;
     }
 }
Пример #7
0
 public override void OnFrame(Leap.Controller controller)
 {
     observer.OnNext(controller.Frame());
 }
Пример #8
0
        public override void OnUpdate()
        {
            // Check for VR mode to prevent desktop input lock
            ms_inVrMode = (bool)m_vrCheckMethod.Invoke(null, null);

            if (ms_enabled)
            {
                // Use Leap Motion data
                if (m_leapActive && m_leapController.IsConnected)
                {
                    var l_frame = m_leapController.Frame();
                    if (l_frame != null)
                    {
                        GestureMatcher.GetGestures(ref l_frame, ref m_gesturesData);
                    }
                }

                if (m_sdk3)
                {
                    // Set SDK3 parameters directly, user has to make own avatar with specific parameters
                    var l_expParams          = VRCPlayer.field_Internal_Static_VRCPlayer_0?.prop_VRCAvatarManager_0?.prop_VRCAvatarDescriptor_0?.expressionParameters?.parameters;
                    var l_playableController = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_AnimatorControllerManager_0?.field_Private_AvatarAnimParamController_0?.field_Private_AvatarPlayableController_0;
                    if ((l_expParams != null) && (l_playableController != null))
                    {
                        for (int i = 0; i < l_expParams.Length; i++)
                        {
                            var l_expParam = l_expParams[i];
                            if (l_expParam.name.StartsWith("_HandPresent") && (l_expParam.valueType == VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionParameters.ValueType.Bool))
                            {
                                int l_bufferIndex = -1;
                                if (Int32.TryParse(l_expParam.name.Substring(12), out l_bufferIndex))
                                {
                                    if ((l_bufferIndex >= 0) && (l_bufferIndex <= 1))
                                    {
                                        l_playableController.Method_Public_Boolean_Int32_Single_0(i, m_gesturesData.m_handsPresenses[l_bufferIndex] ? 1.0f : 0.0f); // Fallback, there is separated method for boolean parameters somewhere
                                    }
                                }
                                continue;
                            }
                            if (l_expParam.name.StartsWith("_FingerBend") && (l_expParam.valueType == VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionParameters.ValueType.Float))
                            {
                                int l_bufferIndex = -1;
                                if (Int32.TryParse(l_expParam.name.Substring(11), out l_bufferIndex))
                                {
                                    if ((l_bufferIndex >= 0) && (l_bufferIndex <= 9))
                                    {
                                        l_playableController.Method_Public_Boolean_Int32_Single_0(i, (i < 5) ? m_gesturesData.m_leftFingersBends[i] : m_gesturesData.m_rightFingersBends[i - 5]);
                                    }
                                }
                                continue;
                            }
                            if (l_expParam.name.StartsWith("_FingerSpread") && (l_expParam.valueType == VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionParameters.ValueType.Float))
                            {
                                int l_bufferIndex = -1;
                                if (Int32.TryParse(l_expParam.name.Substring(13), out l_bufferIndex))
                                {
                                    if ((l_bufferIndex >= 0) && (l_bufferIndex <= 9))
                                    {
                                        l_playableController.Method_Public_Boolean_Int32_Single_0(i, (i < 5) ? m_gesturesData.m_leftFingersSpreads[i] : m_gesturesData.m_rightFingersSpreads[i - 5]);
                                    }
                                }
                                continue;
                            }
                        }
                    }
                }

                if (!m_fingersOnly)
                {
                    var l_solver = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_VRIK_0?.solver;
                    if (l_solver != null)
                    {
                        if (m_gesturesData.m_handsPresenses[0])
                        {
                            if (l_solver.leftArm?.target != null)
                            {
                                Vector3    l_newPos = new Vector3(m_gesturesData.m_handsPositons[0].x, m_gesturesData.m_handsPositons[0].y, -m_gesturesData.m_handsPositons[0].z) * 0.001f;
                                Quaternion l_newRot = new Quaternion(-m_gesturesData.m_handsRotations[0].x, -m_gesturesData.m_handsRotations[0].y, m_gesturesData.m_handsRotations[0].z, m_gesturesData.m_handsRotations[0].w);
                                ApplyAdjustment(ref l_newPos, ref l_newRot);

                                Transform l_rootTransform = GetRootTransform(ref l_solver);
                                m_leftTargetPosition = l_rootTransform.position + l_rootTransform.rotation * l_newPos;
                                m_leftTargetRotation = l_rootTransform.rotation * l_newRot;

                                var l_pickupJoint = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_IkController_0?.field_Private_VRCHandGrasper_0?.field_Private_GameObject_0;
                                if (l_pickupJoint != null)
                                {
                                    l_pickupJoint.transform.position = m_leftTargetPosition;
                                    l_pickupJoint.transform.rotation = m_leftTargetRotation;
                                }
                            }
                        }

                        if (m_gesturesData.m_handsPresenses[1])
                        {
                            if (l_solver.rightArm?.target != null)
                            {
                                Vector3    l_newPos = new Vector3(m_gesturesData.m_handsPositons[1].x, m_gesturesData.m_handsPositons[1].y, -m_gesturesData.m_handsPositons[1].z) * 0.001f;
                                Quaternion l_newRot = new Quaternion(-m_gesturesData.m_handsRotations[1].x, -m_gesturesData.m_handsRotations[1].y, m_gesturesData.m_handsRotations[1].z, m_gesturesData.m_handsRotations[1].w);
                                ApplyAdjustment(ref l_newPos, ref l_newRot);

                                Transform l_rootTransform = GetRootTransform(ref l_solver);
                                m_rightTargetPosition = l_rootTransform.position + l_rootTransform.rotation * l_newPos;
                                m_rightTargetRotation = l_rootTransform.rotation * l_newRot;

                                var l_pickupJoint = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_IkController_0?.field_Private_VRCHandGrasper_1?.field_Private_GameObject_0;
                                if (l_pickupJoint != null)
                                {
                                    l_pickupJoint.transform.position = m_rightTargetPosition;
                                    l_pickupJoint.transform.rotation = m_rightTargetRotation;
                                }
                            }
                        }
                    }
                }

                var l_handController = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_HandGestureController_0;
                if (l_handController != null)
                {
                    l_handController.field_Internal_Boolean_0 = true;
                    l_handController.field_Private_EnumNPublicSealedvaKeMoCoGaViOcViDaWaUnique_0 = VRCInputManager.EnumNPublicSealedvaKeMoCoGaViOcViDaWaUnique.Index;

                    for (int i = 0; i < 2; i++)
                    {
                        if (m_gesturesData.m_handsPresenses[i])
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                int l_dataIndex = i * 5 + j;
                                l_handController.field_Private_ArrayOf_VRCInput_0[l_dataIndex].field_Public_Single_0 = 1.0f - ((i == 0) ? m_gesturesData.m_leftFingersBends[j] : m_gesturesData.m_rightFingersBends[j]); // Squeeze
                                l_handController.field_Private_ArrayOf_VRCInput_1[l_dataIndex].field_Public_Single_0 = ((i == 0) ? m_gesturesData.m_leftFingersSpreads[j] : m_gesturesData.m_rightFingersSpreads[j]);    // Spread
                            }
                        }
                    }
                }
            }
        }
        public override void OnFrame(Leap.Controller controller)
        {
            Leap.Frame frame = controller.Frame();

            Leap.InteractionBox interactionBox = frame.InteractionBox;
            _pointerPosition =
                interactionBox.NormalizePoint(frame.Pointables.Frontmost.TipPosition);

            _standardGestures = frame.Gestures();

            foreach (Leap.Gesture gesture in _standardGestures)
            {
                if (gesture.State.Equals(Leap.Gesture.GestureState.STATESTOP))
                {
                    if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPESWIPE))
                    {
                        Print("Finger Swipe Detected");
                        Leap.SwipeGesture       swipe      = new Leap.SwipeGesture(gesture);
                        Events.FingerSwipeEvent swipeEvent = new Events.FingerSwipeEvent(swipe);
                        OnFingerSwipeDetected(swipeEvent);
                    }

                    if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_CIRCLE))
                    {
                        Print("Circle Gesture Detected");
                        Leap.CircleGesture circle      = new Leap.CircleGesture(gesture);
                        Events.CircleEvent circleEvent = new Events.CircleEvent(circle);
                        OnCircleDetected(circleEvent);
                    }

                    if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_SCREEN_TAP))
                    {
                        Print("Screen Tap Detected");
                        Leap.ScreenTapGesture screenTap      = new Leap.ScreenTapGesture(gesture);
                        Events.ScreenTapEvent screenTapEvent = new Events.ScreenTapEvent(screenTap);
                        OnScreenTapDetected(screenTapEvent);
                    }
                }
            }

            Gestures.HandSwipe handSwipe = Gestures.HandSwipe.IsHandSwipe(frame);
            if (handSwipe != null)
            {
                if (handSwipe.State.Equals(Gestures.GestureState.END))
                {
                    Print("Hand Swipe Detected");

                    Events.HandSwipeEvent swipeEvent = new Events.HandSwipeEvent(handSwipe);
                    OnHandSwipeDetected(swipeEvent);
                }
            }

            Gestures.ZoomIn zoomIn = Gestures.ZoomIn.IsZoomIn(frame);
            if (zoomIn != null)
            {
                if (zoomIn.State.Equals(Gestures.GestureState.END))
                {
                    Print("ZoomIn Detected");

                    Events.ZoomInEvent zoomInEvent = new Events.ZoomInEvent(zoomIn);
                    OnZoomInDetected(zoomInEvent);
                }
            }

            Gestures.ZoomOut zoomOut = Gestures.ZoomOut.IsZoomOut(frame);
            if (zoomOut != null)
            {
                if (zoomOut.State.Equals(Gestures.GestureState.END))
                {
                    Print("ZoomOut Detected");

                    Events.ZoomOutEvent zoomOutEvent = new Events.ZoomOutEvent(zoomOut);
                    OnZoomOutDetected(zoomOutEvent);
                }
            }
        }
Пример #10
0
        private bool IsLeapMotionTrackingBone(HumanBodyBones bone)
        {
            Leap.Controller  lc    = IKDataSourceManager.Instance.LeapController;
            Leap.Frame       frame = lc.Frame();
            List <Leap.Hand> hands = frame.Hands;

            bool leftHandTracked  = false;
            bool rightHandTracked = false;

            int numHands = hands.Count;

            for (int i = 0; i < numHands; ++i)
            {
                if (hands[i].IsLeft)
                {
                    leftHandTracked = true;
                }
                else if (hands[i].IsRight)
                {
                    rightHandTracked = true;
                }
            }

            switch (bone)
            {
            // Left hand bones
            case HumanBodyBones.LeftHand:
            case HumanBodyBones.LeftIndexDistal:
            case HumanBodyBones.LeftIndexIntermediate:
            case HumanBodyBones.LeftIndexProximal:
            case HumanBodyBones.LeftLittleDistal:
            case HumanBodyBones.LeftLittleIntermediate:
            case HumanBodyBones.LeftLittleProximal:
            case HumanBodyBones.LeftLowerArm:
            case HumanBodyBones.LeftMiddleDistal:
            case HumanBodyBones.LeftMiddleIntermediate:
            case HumanBodyBones.LeftMiddleProximal:
            case HumanBodyBones.LeftRingDistal:
            case HumanBodyBones.LeftRingIntermediate:
            case HumanBodyBones.LeftRingProximal:
            case HumanBodyBones.LeftThumbDistal:
            case HumanBodyBones.LeftThumbIntermediate:
            case HumanBodyBones.LeftThumbProximal:
                return(leftHandTracked);

            // Right hand bones
            case HumanBodyBones.RightHand:
            case HumanBodyBones.RightIndexDistal:
            case HumanBodyBones.RightIndexIntermediate:
            case HumanBodyBones.RightIndexProximal:
            case HumanBodyBones.RightLittleDistal:
            case HumanBodyBones.RightLittleIntermediate:
            case HumanBodyBones.RightLittleProximal:
            case HumanBodyBones.RightLowerArm:
            case HumanBodyBones.RightMiddleDistal:
            case HumanBodyBones.RightMiddleIntermediate:
            case HumanBodyBones.RightMiddleProximal:
            case HumanBodyBones.RightRingDistal:
            case HumanBodyBones.RightRingIntermediate:
            case HumanBodyBones.RightRingProximal:
            case HumanBodyBones.RightThumbDistal:
            case HumanBodyBones.RightThumbIntermediate:
            case HumanBodyBones.RightThumbProximal:
                return(rightHandTracked);

            // Leap only tracks hands
            default:
                Debug.LogWarningFormat("IKTarget IsLeapMotionTrackingBone: Invalid bone for Leap Motion: {0} - returning false", bone);
                return(false);
            }
        }