Example #1
0
        /// <summary>
        /// Adds a new LeapMotionArticulatedHand to the scene.
        /// </summary>
        /// <param name="handedness">The handedness (Handedness.Left or Handedness.Right) of the hand to be added</param>
        private void OnHandDetected(Handedness handedness)
        {
            // Only create a new hand if the hand does not exist
            if (!trackedHands.ContainsKey(handedness))
            {
                var pointers    = RequestPointers(SupportedControllerType.ArticulatedHand, handedness);
                var inputSource = CoreServices.InputSystem?.RequestNewGenericInputSource($"Leap {handedness} Controller", pointers, InputSourceType.Hand);
                var leapHand    = new EskyLeapMotionArticulatedHand(TrackingState.Tracked, handedness, inputSource);

                // Set pinch thresholds
                leapHand.handDefinition.EnterPinchDistance = enterPinchDistance;
                leapHand.handDefinition.ExitPinchDistance  = exitPinchDistance;

                // Set the leap attachment hand to the corresponding handedness
                if (handedness == Handedness.Left)
                {
                    leapHand.SetAttachmentHands(leftAttachmentHand, LeapMotionServiceProvider);
                }
                else // handedness == Handedness.Right
                {
                    leapHand.SetAttachmentHands(rightAttachmentHand, LeapMotionServiceProvider);
                }

                // Set the pointers for an articulated hand to the leap hand
                foreach (var pointer in pointers)
                {
                    pointer.Controller = leapHand;
                }

                trackedHands.Add(handedness, leapHand);

                CoreServices.InputSystem.RaiseSourceDetected(inputSource, leapHand);
            }
        }
Example #2
0
        /// <inheritdoc />
        public override void Enable()
        {
            base.Enable();
            switch (leapControllerOrientation)
            {
            case EskyLeapControllerOrientation.Headset:
                CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>();
                break;

            case EskyLeapControllerOrientation.Desk:
                GameObject leapProviderDesk = new GameObject("LeapProvider");
                // The LeapServiceProvider does not need to be attached to a camera, but the location of this gameobject is the anchor for the desk hands
                LeapMotionServiceProvider = leapProviderDesk.AddComponent <LeapServiceProvider>();
                // Follow the transform of the main camera by adding the service provider as a child of the main camera
                leapProviderDesk.transform.parent = CameraCache.Main.transform;
                // Apply hand position offset, an offset is required to render the hands in view and in front of the camera
                LeapMotionServiceProvider.transform.position += leapHandsOffset;
                break;

            case EskyLeapControllerOrientation.Esky:
                GameObject LeapProviderEsky = GameObject.Find("LeapMotion");
                if (LeapProviderEsky != null)
                {
                    LeapMotionServiceProvider = LeapProviderEsky.GetComponent <LeapXRServiceProvider>();
                }
                else
                {
                    Debug.LogError("Couldn't find a 'LeapMotion' game object in scene, the Esky Leapmotion provider needs this!");
                }
                break;
            }
            // Add the attachment hands to the scene for the purpose of getting the tracking state of each hand and joint positions
            GameObject leapAttachmentHandsGameObject = new GameObject("LeapAttachmentHands");

            leapAttachmentHands = leapAttachmentHandsGameObject.AddComponent <AttachmentHands>();

            // The first hand in attachmentHands.attachmentHands is always left
            leftAttachmentHand = leapAttachmentHands.attachmentHands[0];

            // The second hand in attachmentHands.attachmentHands is always right
            rightAttachmentHand = leapAttachmentHands.attachmentHands[1];

            // Enable all attachment point flags in the leap hand. By default, only the wrist and the palm are enabled.
            foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint)))
            {
                leapAttachmentHands.attachmentPoints |= EskyLeapMotionArticulatedHand.ConvertMRTKJointToLeapJoint(joint);
            }
        }