概要
Leap Motion + Unity 2017.3 + Mac で、3Dお絵かきアプリを開発してみました。
Leap MotionのUnity向けのパッケージ「LeapMotionCoreAssets」をベースにしています。
leapmotion/LeapMotionCoreAssets
前提条件
Unityの初歩的知識(シーンについてなど)、使い方が理解できていること。
以下のサイトなどで使い方を学習しておくとよいでしょう。
Unity 概要 - Unity マニュアル
環境
以下の環境で開発しました。
- Leap Motion ソフトウェア バージョン:2.3.1+31549 Firmware Revision: 1.7.0
- Unity Version 2017.3.1f1 Personal
- MacOS High Sierra バージョン 10.13.3
開発環境構築
Leap Motionのセットアップ
以下のサイトより、Leap Motionのセットアップを行います。
Desktop Setup — Leap Motion
Unityのインストール
以下のサイトを参考に、Unityのインストールを行います。
[Unity2017.3をMacにインストールする]
(https://qiita.com/shiutk/items/69b8ceaea0be09dcebea)
Unityでプロジェクトを新規作成
まず、Unityを起動し、「New Project」をクリックします。

次に、Project nameとLocationを設定します。
一例として、Project nameを「3DPainting」、Locationを「/Users/ユーザ名/UnityProjects」に設定します。

そして、「Create project」をクリックすると、先ほど作成したプロジェクトが開きます。

LeapMotionCoreAssetsのインポート
まず、以下のサイトより、LeapMotionCoreAssetsをダウンロードします。
バージョンは「2.3.0」にします。
(それより上のバージョンだとMacに対応していない模様。。)
Release Leap Motion Core Assets v2.3.0 · leapmotion/LeapMotionCoreAssets · GitHub
次に、「Assets」 -> 「Import Package」 -> 「Custom Package...」を選択し、ダウンロードしたLeapMotionCoreAssetsをインポートします。
インポート時、以下の画面が表示されますが、「LeapMotion+OVR」と、「OVR」のチェックを外した状態で「Import」をクリックします。(ちなみに、「OVR」とはOculusのことのようです。)

LeapMotionCoreAssetsを使ってみる
一例として、「VoxelHand」を使用してみます。
まず、「Assets/LeapMotion/Scenes」に移動し、「VoxelHand」をダブルクリックします。

すると、シーンが読み込まれるので、画面上部の再生ボタンをクリックします。

そして、LeapMotionに手をかざすと、以下のようにボクセル化された手が出現します。

3Dお絵かきができるようにカスタマイズしてみる
まず、Hierarchyから「VoxelHand」を選択し、「Add Component」をクリックします。

次に、検索欄に「Trigger」と入力し、「Trigger Drawing」を選択します。
すると、VoxelHandにTrigger DrawingがComponentとして追加されます。

同様の手順で、「Line Renderer」もComponentとして追加します。

追加できたら、先ほどと同様に画面上部の再生ボタンをクリックします。
そして、LeapMotionに手をかざして、人差し指を指した状態で動かすと、指でなぞった部分が以下のように黒く描画されます。

作成したソースコード
以下にありますので、ご自由にお使いください。
hiesiea/3DPainting