BvhBone.cs
1.83 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
using System.Collections.Generic;
using UnityEngine;
namespace UniHumanoid
{
public class BvhBone : IBone
{
public string Name
{
private set;
get;
}
public Vector3 SkeletonLocalPosition
{
private set;
get;
}
public BvhBone(string name, Vector3 position)
{
Name = name;
SkeletonLocalPosition = position;
}
public override string ToString()
{
return string.Format("<BvhBone: {0}>", Name);
}
public IBone Parent
{
private set;
get;
}
List<IBone> _children = new List<IBone>();
public IList<IBone> Children
{
get { return _children; }
}
public void Build(Transform t)
{
foreach (Transform child in t)
{
var childBone = new BvhBone(child.name, SkeletonLocalPosition + child.localPosition);
childBone.Parent = this;
_children.Add(childBone);
childBone.Build(child);
}
}
public void Build(BvhNode node)
{
foreach (var child in node.Children)
{
var childBone = new BvhBone(child.Name, SkeletonLocalPosition + child.Offset.ToXReversedVector3());
childBone.Parent = this;
_children.Add(childBone);
childBone.Build(child);
}
}
public IEnumerable<BvhBone> Traverse()
{
yield return this;
foreach (var child in Children)
{
foreach (var x in child.Traverse())
{
yield return (BvhBone)x;
}
}
}
}
}