トマシープが学ぶ

Unity/VR/AR/デザイン好きのミーハー 記事内容は自分用のメモです

【Oculus】ハンドトラッキングモードかコントローラーかを判定する【Unity】

OculusQuestで今コントローラーモードなのかハンドトラッキングモードなのかってどうやって判定するんだろう?

結論から言うと

OVRInput.GetActiveController()== OVRInput.Controller.Hands

みたいな感じで取れる。他にもいい方法があるかもしれない

OVRHandTest.cs

OVRHandTest.csというサンプルスクリプトにいろいろ状態取得があった!

f:id:bibinbaleo:20200210103103p:plain

動かしたときの記事はこちら

【OculusHandTracking】環境構築とサンプルシーンを見る【Unity】 - トマシープが学ぶ

 

		OVRInput.Controller activeController = OVRInput.GetActiveController();

		string activeControllerName = activeController.ToString();
		data.AppendFormat("Active: {0}\n", activeControllerName);

		string connectedControllerNames = OVRInput.GetConnectedControllers().ToString();
		data.AppendFormat("Connected: {0}\n", connectedControllerNames);

		data.AppendFormat("PrevConnected: {0}\n", prevConnected);

 

OVRInput.GetActiveController()

これで今のコントローラーの種類が取得できる。

f:id:bibinbaleo:20200210104843p:plain

GetConnectedControllersだと接続しているすべてのコントローラーが表示される。(接続とは・・・?)

prevConnectedは一つ前に接続していたコントローラーかな?よくわからない

f:id:bibinbaleo:20200210105144p:plain

というわけで

OVRInput.GetActiveController()== OVRInput.Controller.Hands

みたいな感じで取れる。

切り替わりの監視

update()でずっと監視するのはよくないよね?

UniRxみたいに変わったときに毎回1回だけ実行したい。

 

OVRHandTest.csにBoolMonitorあたりがそれっぽい?

static BoolMonitor controllers = new BoolMonitor("Controllers Changed", () => { return OVRInput.GetConnectedControllers().ToString() != prevConnected; });

 

controllers.Update();

controllers.AppendToStringBuilder(ref data);

prevConnected = connectedControllerNames;

それっぽいけど使い方がよくわからない

isHandTracked

OVRHand.csのIsTrackedで手がトラッキングされてるかが分かる。

 

Tracking Hands and Confidence Level

At any point, your app logic may want to check if your app detects hands. OVRHand.cs provides the IsTracked property to verify whether hands are currently visible and otherwise not occluded from being tracked by the device. It also provides the HandConfidence property that indicates the level of confidence the tracking system has for the overall hand pose. The property returns the confidence level as HandConfidence values, either Low or High.

公式ドキュメントより

developer.oculus.com

 

でもこれってハンドトラッキングモードで、かつ手が見えてる時ってことだよね~

おまけ:OVRPluginのHand

OVRPluginのHandには何が入ってるのかな?

f:id:bibinbaleo:20200207164328p:plain

f:id:bibinbaleo:20200207164224p:plain

if (OVRPlugin.GetHandState(step, (OVRPlugin.Hand)HandType, ref _handState))