Skeleton.cs
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Collections.Generic;
using UnityEngine;
namespace UniHumanoid
{
/// <summary>
/// Mapping HumanBodyBones to BoneIndex
/// </summary>
public struct Skeleton
{
Dictionary<HumanBodyBones, int> m_indexMap;
public Dictionary<HumanBodyBones, int> Bones
{
get { return m_indexMap; }
}
public int GetBoneIndex(HumanBodyBones bone)
{
int index;
if (m_indexMap.TryGetValue(bone, out index))
{
return index;
}
else
{
return -1;
}
}
#if UNITY_EDITOR
/// <summary>
/// For UnitTest
/// </summary>
Dictionary<HumanBodyBones, string> m_nameMap;
/// <summary>
/// ForTest
/// </summary>
/// <param name="bone"></param>
/// <returns></returns>
public string GetBoneName(HumanBodyBones bone)
{
string name;
if (m_nameMap.TryGetValue(bone, out name))
{
return name;
}
else
{
return null;
}
}
#endif
public static Skeleton Estimate(Transform hips)
{
var estimater = new BvhSkeletonEstimator();
return estimater.Detect(hips);
}
/// <summary>
/// Register bone's HumanBodyBones
/// </summary>
/// <param name="bone"></param>
/// <param name="bones"></param>
/// <param name="b"></param>
public void Set(HumanBodyBones bone, IList<IBone> bones, IBone b)
{
if (b != null)
{
Set(bone, bones.IndexOf(b), b.Name);
}
}
public void Set(HumanBodyBones bone, int index, string name)
{
if (m_indexMap == null)
{
m_indexMap = new Dictionary<HumanBodyBones, int>();
}
m_indexMap[bone] = index;
#if UNITY_EDITOR
if (m_nameMap == null)
{
m_nameMap = new Dictionary<HumanBodyBones, string>();
}
m_nameMap[bone] = name;
#endif
}
}
}