メインコンテンツへスキップ
見出し画像

Meta Quest Pro で ボディトラッキングを試す

    「Meta Quest Pro」 で ボディトラッキングを試したのでまとめました。

    ・Meta Quest Pro
    ・Oculus Integration v46.0
    ・Unity 2021.3.10f1

    1. ボディトラッキング

    ヘッドセットとハンドコントローラの動きから、プレイヤーの姿勢を検出します。プレイヤーの姿勢は、ヒューマノイドリグのジョイントの座標として取得できます。

    2. 開発環境の準備

    Oculus Questアプリと同様です。

    3. ボディトラッキングの追加

    フェイストラッキングの追加手順は、次のとおりです。

    (1) Hierarchyウィンドウに空のゲームオブジェクトを追加し、「BodyController」と名前を指定し、「OVRBody」を追加。

    画像

    (2) ゲームオブジェクト「BodyController」に新規スクリプト「BodyController」を追加。

    画像

    ・BodyController.cs

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class BodyController : MonoBehaviour
    {
        GameObject[] points = new GameObject[70];
        OVRBody ovrBody;
    
        // スタート時に呼ばれる
        void Start()
        {
            // ポイント群の生成
            for (int i = 0; i < 70; i ++)
            {
                points[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                if (i < 18)
                {
                    points[i].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                }
                else
                {
                    points[i].transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
                }
            }
    
            // 参照
            ovrBody = GetComponent<OVRBody>();
        }
    
        // フレーム更新毎に呼ばれる
        void Update()
        {
            // ボディトラッキングの有効時
            if (ovrBody != null && ovrBody.BodyState != null)
            {
                OVRPlugin.BodyState bodyState = (OVRPlugin.BodyState)ovrBody.BodyState;
    
                // ポイント群の更新
                for (int i = 0; i < 70; i++)
                {
                    OVRPlugin.Posef pose = bodyState.JointLocations[i].Pose;
                    Vector3 pos = this.points[i].transform.position;
                    pos.x = pose.Position.x;
                    pos.y = pose.Position.y;
                    pos.z = pose.Position.z+1;
                    this.points[i].transform.position = pos;
                }
            }
        }
    }

    「OVRBody」のAPIリファレンスは、次のとおりです。

    ・OVRBodyのAPIリファレンス

    (3) HierarchyウィンドウにShpereを追加して非アクティブ化。
    追加しておかないと、実機でSphereが表示されなかったので、ひとまず追加してます。(後で原因調べる)

    画像

    (4)  「OVRCameraRig」の「Hand Tracking Support」に「Controllers And Hands」、「General → Body Tracking Support」に「Required」を指定。

    画像

    (4)  「OVRCameraRig」の「Permission Requests On Startup → Body Tracking」をチェック。

    画像

    4. ボディトラッキングの実行 

    ボディトラッキングの実行手順は、次のとおりです。

    (1) アクセス許可のダイアログが表示されるので、許可ボタンを押す。

    画像

    (2) 自分の姿勢が同期するのを確認。

    画像
    画像

    5. 関連

    【おまけ】 ジョイントロケーションの定数一覧

    ボディトラッキングのジョイントロケーションの定数一覧は、次のとおりです。

        private const int Root = 0;
        private const int Hips = 1;
        private const int SpineLower = 2;
        private const int SpineMiddle = 3;
        private const int SpineUpper = 4;
        private const int Chest = 5;
        private const int Neck = 6;
        private const int Head = 7;
        private const int LeftShoulder = 8;
        private const int LeftScapula = 9;
        private const int LeftArmUpper = 10;
        private const int LeftArmLower = 11;
        private const int LeftHandWristTwist = 12;
        private const int RightShoulder = 13;
        private const int RightScapula = 14;
        private const int RightArmUpper = 15;
        private const int RightArmLower = 16;
        private const int RightHandWristTwist = 17;
        private const int LeftHandPalm = 18;
        private const int LeftHandWrist = 19;
        private const int LeftHandThumbMetacarpal = 20;
        private const int LeftHandThumbProximal = 21;
        private const int LeftHandThumbDistal = 22;
        private const int LeftHandThumbTip = 23;
        private const int LeftHandIndexMetacarpal = 24;
        private const int LeftHandIndexProximal = 25;
        private const int LeftHandIndexIntermediate = 26;
        private const int LeftHandIndexDistal = 27;
        private const int LeftHandIndexTip = 28;
        private const int LeftHandMiddleMetacarpal = 29;
        private const int LeftHandMiddleProximal = 30;
        private const int LeftHandMiddleIntermediate = 31;
        private const int LeftHandMiddleDistal = 32;
        private const int LeftHandMiddleTip = 33;
        private const int LeftHandRingMetacarpal = 34;
        private const int LeftHandRingProximal = 35;
        private const int LeftHandRingIntermediate = 36;
        private const int LeftHandRingDistal = 37;
        private const int LeftHandRingTip = 38;
        private const int LeftHandLittleMetacarpal = 39;
        private const int LeftHandLittleProximal = 40;
        private const int LeftHandLittleIntermediate = 41;
        private const int LeftHandLittleDistal = 42;
        private const int LeftHandLittleTip = 43;
        private const int RightHandPalm = 44;
        private const int RightHandWrist = 45;
        private const int RightHandThumbMetacarpal = 46;
        private const int RightHandThumbProximal = 47;
        private const int RightHandThumbDistal = 48;
        private const int RightHandThumbTip = 49;
        private const int RightHandIndexMetacarpal = 50;
        private const int RightHandIndexProximal = 51;
        private const int RightHandIndexIntermediate = 52;
        private const int RightHandIndexDistal = 53;
        private const int RightHandIndexTip = 54;
        private const int RightHandMiddleMetacarpal = 55;
        private const int RightHandMiddleProximal = 56;
        private const int RightHandMiddleIntermediate = 57;
        private const int RightHandMiddleDistal = 58;
        private const int RightHandMiddleTip = 59;
        private const int RightHandRingMetacarpal = 60;
        private const int RightHandRingProximal = 61;
        private const int RightHandRingIntermediate = 62;
        private const int RightHandRingDistal = 63;
        private const int RightHandRingTip = 64;
        private const int RightHandLittleMetacarpal = 65;
        private const int RightHandLittleProximal = 66;
        private const int RightHandLittleIntermediate = 67;
        private const int RightHandLittleDistal = 68;
        private const int RightHandLittleTip = 69;



     
     

    npaka

     
     
    プログラマー。iPhone / Android / Unity / ROS / AI / AR / VR / RasPi / ロボット / ガジェット。年2冊ペースで技術書を執筆。アニソン / カラオケ / ギター / 猫 twitter : @npaka123

    あなたへのおすすめ