LoginSignup
13
13

More than 5 years have passed since last update.

UnityでLeapMotion 新SDK Orion

Posted at

2016年初頭、Leap Motionの新しいドライバ、SDKとしてOrionがリリースされています。

本家ドキュメント
https://developer.leapmotion.com/documentation/unity/api/Leap_Classes.html

詳しい解説はこちら。
http://qiita.com/afjk/items/e2c9617e937528feba6e
http://zabaglione.info/archives/789

Orion VR(Beta) と記載されているくらいなので、おもにVR関連が強化されているのだと思います。
VRを使用しない場合もUnityでLeap Motionを扱いたい場合はOrionを使うのが楽です。
(過去にはアセットストアにSDKがおいてあったと思うのですが無くなってしまいました)

LeapMotion_CoreAsset_Orion_4.1.1.unitypackage
をプロジェクトにインポートして使います。
デモシーンが含まれているのでさくっと動作確認までは簡単です。

デモシーンなどに使われているのはほぼnamespace Leap.Unity のクラスで主なところをピックアップすると
LeapHandController
LeapServiceProvider
等です。
サンプルと同じように namespace Leap.Unity にあるクラス群を自作アプリにそのまま使ってもよいのですが、多少まわりくどかったり、ややこしめに作られていたり、なのでシンプルに自分の欲しい機能だけ取り出して使う分には namespace Leap のクラスを直接操作するほうがわかりやすいです。

http://qiita.com/amano-kiyoyuki/items/7bbb84ae586aca034d54
↑は(たぶん)v1のときのサンプルだと思うのですがOrionではビルドも通らなくなってしまっているのでこれのアップデート版サンプルを以下に記載します。

sample.cs

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

public class LeapSample : MonoBehaviour
{
    Controller controller;


    public GameObject[] FingerObjects;


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

    void OnApplicationQuit()
    {
        if(controller!=null)
        {
            controller.StopConnection();
            controller.Dispose();
            controller = null;
        }
    }


    void Update()
    {
        Frame       frame   = controller.Frame();
        List<Hand>  hands   = frame.Hands;

        if( 0 < hands.Count )
        {
            Hand            firstHand   = hands[0];
            List<Finger>    fingers     = firstHand.Fingers;

            for( int ii=0; ii<fingers.Count; ++ii )
            {
                Finger  finger      = fingers[ii];
                var     fingerObj   = FingerObjects[ii];
                Vector  v           = finger.TipPosition;

                fingerObj.transform.position = UnityVectorExtension.ToVector3( v ) / 10;
            }
        }
    }
}

特に重要なのは
controller.StopConnection();
でしょうか。
これを忘れると、UnityEditorがLeapMotionの何かを掴みっぱなしにするらしく、
そのまま無限ループに突入してUnityが死にます。ご注意ください。

UnityVectorExtension.ToVector3( v ) / 10;
の10で割ってるのは特に意味ないです。座標数値はLeap Motionからのリアルな距離数値、ミリメートルで値が返ってくるので大きすぎるので適当に小さくしただけです…

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13