なんかいろいろしてみます

Mar 11, 2020 - 1 minute read - HoloLens

HoloLens 2で利用できるジェスチャー入力について(Unity 2018編)

Unity 2018からHoloLens 2で行うジェスチャー入力の実装方法について書いてます.

Unity 2019.3以降ではUnityEngine.XR.WSA.Inputに替わってWindows XR Pluginの利用が推奨されています.

Unity 2018までのHoloLens開発環境の設定項目

Unity 2018.4でHoloLens用の開発環境の準備

  • UWPコンポーネントのインストール
  • Build SettingsのPlatformをUWPに変更
  • PlayerSettingsのXR SettingsのVirtual Reality Supported有効にしてWindows Mixed Realityを追加

InteractionManagerの機能

HoloLens 1での利用方法はこちらのHoloLensで利用できるジェスチャー入力について(Unity 2017.2編)

HoloLens 1とWindows MRデバイス(VR),HoloLens 2のジェスチャー入力が取得できます.

また基本的な関数の利用はHoloLens 1と同様に行えますが,HoloLens 2ではより詳細にハンド情報の取得が行えます.

  • InteractionSourceDetected : ハンドの検出開始
  • InteractionSourceLost : ハンドの検出終了
  • InteractionSourcePressed : ハンドのAirTap開始
  • InteractionSourceReleased : ハンドのAirTap終了
  • InteractionSourceUpdated : ハンドの検出中の更新
1
using UnityEngine.XR.WSA.Input;
 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233
    void Start()
    {
        InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected;
        InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost;
        InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed;
        InteractionManager.InteractionSourceReleased += InteractionManager_InteractionSourceReleased;
        InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
    }

    private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
    {
        // Update
    }

    private void InteractionManager_InteractionSourceReleased(InteractionSourceReleasedEventArgs obj)
    {
        // Release
    }

    private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs obj)
    {
        // Press
    }

    private void InteractionManager_InteractionSourceLost(InteractionSourceLostEventArgs obj)
    {
        // Lost
    }

    private void InteractionManager_InteractionSourceDetected(InteractionSourceDetectedEventArgs obj)
    {
        // Detect
    }

HoloLens 2ではHoloLens 1には無かった

  • ハンドの左右判別
  • ハンドの位置と回転

が取得でき,AirTapのポーズをとらなくてもトラッキングが行えます.

 1 2 3 4 5 6 7 8 91011121314151617181920
    private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
    {
        // Update
        Vector3 pos;
        Quaternion rot;
        if (obj.state.sourcePose.TryGetPosition(out pos))
        {
            if (obj.state.sourcePose.TryGetRotation(out rot))
            {
                if (obj.state.source.handedness == InteractionSourceHandedness.Right)
                {
                    // Right Hand
                }
                else if (obj.state.source.handedness == InteractionSourceHandedness.Left)
                {
                    // Left Hand
                }
            }
        }
    }

ただしInteractionManagerから取得できるのはハンドの中心位置とジェスチャーのみなので,Hand Meshや手の関節情報の取得は行えません.

実際にInteractionManagerを利用して両手のハンドを利用した動画とサンプルプロジェクトが以下になります.

GitHub : HoloLens2InputSampleWithUnity

まとめ

  • Unity 2019.3以降ではUnityEngine.XR.WSA.Inputに替わってWindows XR Pluginの利用が推奨されています.
  • HoloLens 1から追従性とジェスチャーの精度が格段に向上している
  • Hand Meshや関節情報の取得は行えない