LoginSignup
1
1

More than 1 year has passed since last update.

AzureKinectをUnity Humanoidにアタッチするためのメモ

Posted at

Unityでアバターを動かす必要があったためAzureKinectの骨格検出を利用してのアタッチを試みた。

AzureKinect自体の環境構築は別記事。

Azure-Kinect-SamplesにUnity他、BodyTracking系の様々なサンプルプログラムが格納されているのでクローン

Azure-Kinect-Samples/body-tracking-samples/sample_unity_bodytrackingにあるREADME.mdを読みながらUnityプロジェクトの環境構築。事前にAzureKinect自体の環境構築が必要。

3)のMoveLibraryFiles.batを実行中に2つのファイルが見つからないエラーが出るが、問題なかった。
自分の場合、いくつかのファイルがリスト通りに配置されないものもあったのでリストと目grepしながら問題ないか確認する。

Unityを起動してプロジェクトフォルダを開き、Kinect4AzureSampleSceneを実行するとrtx30系に起因するエラーが吐き出された。SkeletalTrackingProvider.csの46行目、

SkeletalTrackingProviders.cs (46)
using (Tracker tracker = Tracker.Create(deviceCalibration, new TrackerConfiguration() { ProcessingMode = TrackerProcessingMode.Gpu, SensorOrientation = SensorOrientation.Default }))

TrackerProcessingMode.Cudaに変更することで解決した。

参考になったissue

これで、動いた
スクリーンショット (3).png

骨格がきちんと表示されればOK

次にAzureKinectのBoneIdをUnityのHumanoidのIdにアタッチさせてポジションをリンクさせる。それぞれのIdは以下参照。
https://docs.microsoft.com/ja-jp/azure/kinect-dk/body-joints
https://docs.unity3d.com/ScriptReference/HumanBodyBones.html

HumanBodyBones enumの中身は以下(記述が冗長なのはご愛嬌...)

#region アセンブリ UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// C:\Program Files\Unity\Hub\Editor\2021.1.15f1\Editor\Data\Managed\UnityEngine\UnityEngine.AnimationModule.dll
#endregion

namespace UnityEngine
{
    //
    // 概要:
    //     Human Body Bones.
    public enum HumanBodyBones
    {
        //
        // 概要:
        //     This is the Hips bone.
        Hips = 0,
        //
        // 概要:
        //     This is the Left Upper Leg bone.
        LeftUpperLeg = 1,
        //
        // 概要:
        //     This is the Right Upper Leg bone.
        RightUpperLeg = 2,
        //
        // 概要:
        //     This is the Left Knee bone.
        LeftLowerLeg = 3,
        //
        // 概要:
        //     This is the Right Knee bone.
        RightLowerLeg = 4,
        //
        // 概要:
        //     This is the Left Ankle bone.
        LeftFoot = 5,
        //
        // 概要:
        //     This is the Right Ankle bone.
        RightFoot = 6,
        //
        // 概要:
        //     This is the first Spine bone.
        Spine = 7,
        //
        // 概要:
        //     This is the Chest bone.
        Chest = 8,
        //
        // 概要:
        //     This is the Neck bone.
        Neck = 9,
        //
        // 概要:
        //     This is the Head bone.
        Head = 10,
        //
        // 概要:
        //     This is the Left Shoulder bone.
        LeftShoulder = 11,
        //
        // 概要:
        //     This is the Right Shoulder bone.
        RightShoulder = 12,
        //
        // 概要:
        //     This is the Left Upper Arm bone.
        LeftUpperArm = 13,
        //
        // 概要:
        //     This is the Right Upper Arm bone.
        RightUpperArm = 14,
        //
        // 概要:
        //     This is the Left Elbow bone.
        LeftLowerArm = 15,
        //
        // 概要:
        //     This is the Right Elbow bone.
        RightLowerArm = 16,
        //
        // 概要:
        //     This is the Left Wrist bone.
        LeftHand = 17,
        //
        // 概要:
        //     This is the Right Wrist bone.
        RightHand = 18,
        //
        // 概要:
        //     This is the Left Toes bone.
        LeftToes = 19,
        //
        // 概要:
        //     This is the Right Toes bone.
        RightToes = 20,
        //
        // 概要:
        //     This is the Left Eye bone.
        LeftEye = 21,
        //
        // 概要:
        //     This is the Right Eye bone.
        RightEye = 22,
        //
        // 概要:
        //     This is the Jaw bone.
        Jaw = 23,
        //
        // 概要:
        //     This is the left thumb 1st phalange.
        LeftThumbProximal = 24,
        //
        // 概要:
        //     This is the left thumb 2nd phalange.
        LeftThumbIntermediate = 25,
        //
        // 概要:
        //     This is the left thumb 3rd phalange.
        LeftThumbDistal = 26,
        //
        // 概要:
        //     This is the left index 1st phalange.
        LeftIndexProximal = 27,
        //
        // 概要:
        //     This is the left index 2nd phalange.
        LeftIndexIntermediate = 28,
        //
        // 概要:
        //     This is the left index 3rd phalange.
        LeftIndexDistal = 29,
        //
        // 概要:
        //     This is the left middle 1st phalange.
        LeftMiddleProximal = 30,
        //
        // 概要:
        //     This is the left middle 2nd phalange.
        LeftMiddleIntermediate = 31,
        //
        // 概要:
        //     This is the left middle 3rd phalange.
        LeftMiddleDistal = 32,
        //
        // 概要:
        //     This is the left ring 1st phalange.
        LeftRingProximal = 33,
        //
        // 概要:
        //     This is the left ring 2nd phalange.
        LeftRingIntermediate = 34,
        //
        // 概要:
        //     This is the left ring 3rd phalange.
        LeftRingDistal = 35,
        //
        // 概要:
        //     This is the left little 1st phalange.
        LeftLittleProximal = 36,
        //
        // 概要:
        //     This is the left little 2nd phalange.
        LeftLittleIntermediate = 37,
        //
        // 概要:
        //     This is the left little 3rd phalange.
        LeftLittleDistal = 38,
        //
        // 概要:
        //     This is the right thumb 1st phalange.
        RightThumbProximal = 39,
        //
        // 概要:
        //     This is the right thumb 2nd phalange.
        RightThumbIntermediate = 40,
        //
        // 概要:
        //     This is the right thumb 3rd phalange.
        RightThumbDistal = 41,
        //
        // 概要:
        //     This is the right index 1st phalange.
        RightIndexProximal = 42,
        //
        // 概要:
        //     This is the right index 2nd phalange.
        RightIndexIntermediate = 43,
        //
        // 概要:
        //     This is the right index 3rd phalange.
        RightIndexDistal = 44,
        //
        // 概要:
        //     This is the right middle 1st phalange.
        RightMiddleProximal = 45,
        //
        // 概要:
        //     This is the right middle 2nd phalange.
        RightMiddleIntermediate = 46,
        //
        // 概要:
        //     This is the right middle 3rd phalange.
        RightMiddleDistal = 47,
        //
        // 概要:
        //     This is the right ring 1st phalange.
        RightRingProximal = 48,
        //
        // 概要:
        //     This is the right ring 2nd phalange.
        RightRingIntermediate = 49,
        //
        // 概要:
        //     This is the right ring 3rd phalange.
        RightRingDistal = 50,
        //
        // 概要:
        //     This is the right little 1st phalange.
        RightLittleProximal = 51,
        //
        // 概要:
        //     This is the right little 2nd phalange.
        RightLittleIntermediate = 52,
        //
        // 概要:
        //     This is the right little 3rd phalange.
        RightLittleDistal = 53,
        //
        // 概要:
        //     This is the Upper Chest bone.
        UpperChest = 54,
        //
        // 概要:
        //     This is the Last bone index delimiter.
        LastBone = 55
    }
}

以上をもとにそれぞれをアタッチする必要があるとわかる。
具体的には、以下の記事を参考にさせていただき、実装した。

ひとまずここまでで実行できる。

1
1
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
1
1