Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hello. In my project, I use Leap Motion Orion 4.1.0 and SDK 4.4.0 to record the coordinates of the right-hand index fingertip as text data.
The code is as follows, based on https://developer-archive.leapmotion.com/documentation/csharp/api/Leap.Finger.html#id2.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using Leap;
using Leap.Unity;
using UnityEngine.UI;

public class RightHandIndexTip : MonoBehaviour
{
[SerializeField]
GameObject m_ProviderObject;
Controller controller;
LeapServiceProvider m_Provider;

void Start()
{
controller = new Controller();

// Save as text data in the HandData folder on the desktop
using (StreamWriter sw = new StreamWriter(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\HandData\RightHandIndexTip.txt", true))
{
sw.WriteLine("xposition,yposition,zposition,hour:minutes:second.millisecond,year/month/day");
}
}

void Update()
{
var now = DateTime.Now;

    Frame frame = controller.Frame();
    List<Hand> hands = frame.Hands;
    foreach (Hand hand in hands)
    {
        if (hand.IsRight)
        {
            List<Finger> fingers = hand.Fingers;
            foreach (Finger finger in fingers)
            {

        // Obtain coordinates of distal phalanx upper end, Index Tip
var boneT = finger.Bone(Bone.BoneType.TYPE_DISTAL);
Vector positionT = boneT.NextJoint;
string xpositionT = positionT.x.ToString();
string ypositionT = positionT.y.ToString();
string zpositionT = positionT.z.ToString();

                else if (finger.Type == Finger.FingerType.TYPE_INDEX)
                {
                    using (StreamWriter sw = new StreamWriter(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\HandData\RightHandIndexTIP.txt", true))
                    {
                        sw.WriteLine("{0},{1},{2},{3:HH:mm:ss.fff,yyy/MM/dd}", xpositionT, ypositionT, zpositionT, now);
                    }
                }
            }
        }
    }
}

}

However, when using this code with LeapMotion Gemini 5.7.2 and SDK 6.2.1, an error occurs in the Vector part of Vector positionT = boneT.NextJoint;. I am not familiar with Unity, so I don't really understand how Vector and Vector3 work.
I would appreciate it if you could provide me with the fixed code.

You must be logged in to vote

Hi @yukitatsuta

The API documentation you have linked is out of date as it is on the older Leap Motion site (I will look to make this more clear in future) the updated version of the page you referenced is here

As we moved the Unity Plugin to 6.0 we changed the format that our Frame data has. We stopped using our own Vector and began using Unitys built-in Vector3. We have some documentation on this available here

With your code, you would change Vector for Vector3 and your code should continue to work. I would also recommend referencing a specific LeapProvider, rather than creating a Controller yourself (the LeapProviders handle that for you)

Here is an example using your code as a base …

Replies: 1 comment · 1 reply

Comment options

Hi @yukitatsuta

The API documentation you have linked is out of date as it is on the older Leap Motion site (I will look to make this more clear in future) the updated version of the page you referenced is here

As we moved the Unity Plugin to 6.0 we changed the format that our Frame data has. We stopped using our own Vector and began using Unitys built-in Vector3. We have some documentation on this available here

With your code, you would change Vector for Vector3 and your code should continue to work. I would also recommend referencing a specific LeapProvider, rather than creating a Controller yourself (the LeapProviders handle that for you)

Here is an example using your code as a base (the code you have shared is missing some lines inside the foreach loop, but hopefully you can understand what I mean):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using Leap;
using Leap.Unity;
using UnityEngine.UI;

public class RightHandIndexTip : MonoBehaviour
{
    [SerializeField]
    GameObject m_ProviderObject;

    [SerializeField]
    LeapProvider m_Provider;

    void Start()
    {
        if (m_Provider == null)
        {
            m_Provider = m_ProviderObject.GetComponent<LeapProvider>();
        }

        // Save as text data in the HandData folder on the desktop
        using (StreamWriter sw = new StreamWriter(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\HandData\RightHandIndexTip.txt", true))
        {
            sw.WriteLine("xposition,yposition,zposition,hour:minutes:second.millisecond,year/month/day");
        }
    }

    void Update()
    {
        var now = DateTime.Now;

        Frame frame = m_Provider.CurrentFrame;
        List<Hand> hands = frame.Hands;
        foreach (Hand hand in hands)
        {
            if (hand.IsRight)
            {
                List<Finger> fingers = hand.Fingers;
                foreach (Finger finger in fingers)
                {
                    // Obtain coordinates of distal phalanx upper end, Index Tip
                    var boneT = finger.Bone(Bone.BoneType.TYPE_DISTAL);
                    Vector3 positionT = boneT.NextJoint;
                    string xpositionT = positionT.x.ToString();
                    string ypositionT = positionT.y.ToString();
                    string zpositionT = positionT.z.ToString();

                    //else if (finger.Type == Finger.FingerType.TYPE_INDEX)
                    //{
                    //    using (StreamWriter sw = new StreamWriter(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\HandData\RightHandIndexTIP.txt", true))
                    //    {
                    //        sw.WriteLine("{0},{1},{2},{3:HH:mm:ss.fff,yyy/MM/dd}", xpositionT, ypositionT, zpositionT, now);
                    //    }
                    //}
                }
            }
        }
    }
}
You must be logged in to vote
1 reply
@yukitatsuta
Comment options

Hello @MattGrayUL
I was very surprised and grateful for the quick response. I understand the differences between past and current versions and how to modify Vector for Vector3. I modified my past code with yours and set up LeapProvider, and it works as intended. Thank you very much.

Answer selected by yukitatsuta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.