Пример #1
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);
            }
        }
        /// <inheritdoc />
        public override void Enable()
        {
            base.Enable();

            if (leapControllerOrientation == LeapControllerOrientation.Headset)
            {
                // If the leap controller is mounted on a headset then add the LeapXRServiceProvider to the scene
                // The LeapXRServiceProvider can only be attached to a camera
                LeapMotionServiceProvider = CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>();
            }

            if (leapControllerOrientation == LeapControllerOrientation.Desk)
            {
                // Create a separate gameobject if the leap controller is on the desk
                GameObject leapProvider = 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 = leapProvider.AddComponent <LeapServiceProvider>();

                // Follow the transform of the main camera by adding the service provider as a child of the main camera
                leapProvider.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;
            }

            // 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 |= LeapMotionArticulatedHand.ConvertMRTKJointToLeapJoint(joint);
            }
        }
Пример #3
0
        /// <inheritdoc />
        public override void Enable()
        {
            base.Enable();

            if (leapControllerOrientation == LeapControllerOrientation.Headset)
            {
                // As of the Unity Plugin (>V5.0.0), the leap service provider needs to know what is the main camera,
                // it will pick this up from the MainCameraProvider. This needs to be done before the LeapXRServiceProvider is created

#if LEAPMOTIONPLUGIN_PRESENT
                MainCameraProvider.mainCamera = CameraCache.Main;
#endif
                // If the leap controller is mounted on a headset then add the LeapXRServiceProvider to the scene
                LeapMotionServiceProvider = CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>();

                // Allow modification of VR specific offset modes if the leapControllerOrientation is Headset
                // These settings mirror the modification of the properties exposed in the inspector within the LeapXRServiceProvider attached
                // to the main camera
                if (leapVRDeviceOffsetMode == LeapVRDeviceOffsetMode.ManualHeadOffset)
                {
                    // Change the offset mode before setting the properties
                    leapXRServiceProvider.deviceOffsetMode = LeapXRServiceProvider.DeviceOffsetMode.ManualHeadOffset;

                    leapXRServiceProvider.deviceOffsetYAxis = SettingsProfile.LeapVRDeviceOffsetY;
                    leapXRServiceProvider.deviceOffsetZAxis = SettingsProfile.LeapVRDeviceOffsetZ;
                    leapXRServiceProvider.deviceTiltXAxis   = SettingsProfile.LeapVRDeviceOffsetTiltX;
                }
                else if (leapVRDeviceOffsetMode == LeapVRDeviceOffsetMode.Transform)
                {
                    if (SettingsProfile.LeapVRDeviceOrigin != null)
                    {
                        leapXRServiceProvider.deviceOffsetMode = LeapXRServiceProvider.DeviceOffsetMode.Transform;

                        leapXRServiceProvider.deviceOrigin = SettingsProfile.LeapVRDeviceOrigin;
                    }
                    else
                    {
                        Debug.LogError("The Leap VR Device Origin Transform was not set in the LeapMotionDeviceManagerProfile and is null.");
                    }
                }
            }

            if (leapControllerOrientation == LeapControllerOrientation.Desk)
            {
                // Create a separate gameobject if the leap controller is on the desk
                GameObject leapProvider = 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 = leapProvider.AddComponent <LeapServiceProvider>();

                // Follow the transform of the main camera by adding the service provider as a child of the main camera
                leapProvider.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;
            }

            // 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 |= LeapMotionArticulatedHand.ConvertMRTKJointToLeapJoint(joint);
            }
        }
Пример #4
0
        /// <inheritdoc />
        public override void Enable()
        {
            base.Enable();

            if (leapControllerOrientation == LeapControllerOrientation.Headset)
            {
                // If the leap controller is mounted on a headset then add the LeapXRServiceProvider to the scene
                // The LeapXRServiceProvider can only be attached to a camera
                LeapMotionServiceProvider = CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>();
                //If northstar driver is installed, we need to get the LeapOffset values from the .vrsettings file
                //LeapMotionServiceProvider.GetComponent<LeapXRServiceProvider>().deviceOffsetMode = Leap.Unity.LeapXRServiceProvider.DeviceOffsetMode.Transform;
                //private Transform LeapOrigin = GetLeapOffset();
                //LeapMotionServiceProvider.GetComponent<LeapXRServiceProvider>().deviceOrigin = LeapOrigin
                //private Transform LeapOrigin = 0;
                //C:\Program Files (x86)\Steam\steamapps\common\SteamVR\drivers\northstar\resources\settings\default.vrsettings
                string path = @"c:\Program Files (x86)\Steam\steamapps\common\SteamVR\drivers\northstar\resources\settings\default.vrsettings";
                //path = "";

                if (System.IO.File.Exists(path))
                {
                    //Check if we have a valid calibration to read
                    Debug.Log(path + "exists");
                    //Create game object to apply sensor offset
                    GameObject leapProvider = new GameObject("LeapProvider");
                    //Read in data from calibration file
                    string headsetsettings = System.IO.File.ReadAllText(path);
                    Debug.Log(headsetsettings);
                    //Parse data

                    Calibration headset = JsonUtility.FromJson <Calibration>(headsetsettings);

                    Leaptrackerodometryorigin leapoffset = headset.leapTrackerOdometryOrigin;

                    Debug.Log("headset : --" + headset.leapTrackerOdometryOrigin);

                    Vector3    leapposition = new Vector3(leapoffset.position_x, leapoffset.position_y, leapoffset.position_z);
                    Quaternion leaprotation = new Quaternion(leapoffset.rotation_x, leapoffset.rotation_y, leapoffset.rotation_z, leapoffset.rotation_w);
                    //Apply leap offset
                    Leap.Unity.Pose pose = new Leap.Unity.Pose(leapposition, leaprotation);
                    leapProvider.transform.SetLocalPose(pose);

                    LeapMotionServiceProvider.GetComponent <LeapXRServiceProvider>().deviceOrigin     = leapProvider.transform;
                    LeapMotionServiceProvider.GetComponent <LeapXRServiceProvider>().deviceOffsetMode = Leap.Unity.LeapXRServiceProvider.DeviceOffsetMode.Transform;
                    Debug.Log("Applied Leap Offset from North Star vrsettings");
                }
                else
                {
                    Debug.Log(path + " not found, setting default Leap Offset");
                    LeapMotionServiceProvider = CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>();
                }
            }

            if (leapControllerOrientation == LeapControllerOrientation.Desk)
            {
                // Create a separate gameobject if the leap controller is on the desk
                GameObject leapProvider = 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 = leapProvider.AddComponent <LeapServiceProvider>();

                // Follow the transform of the main camera by adding the service provider as a child of the main camera
                leapProvider.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;
            }

            // 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 |= LeapMotionArticulatedHand.ConvertMRTKJointToLeapJoint(joint);
            }
        }