public static void CalcRelative(SkinBone me, Matrix parent) { foreach (var c in me.Children) { CalcRelative(c, me.Offset); } me.Init *= parent; }
public BoneManager(MmdBone[] bones) { Bones = new List <SkinBone>(); Roots = new List <SkinBone>(); for (int i = 0; i < bones.Length; i++) { Bones.Add(new SkinBone(bones, i)); if (MaxRank < bones[i].Rank) { MaxRank = bones[i].Rank; } if (bones[i].ParentIndex == -1) { Roots.Add(Bones[i]); } } for (int i = 0; i < bones.Length; i++) { if (bones[i].ParentIndex >= 0) { Bones[i].Parent = Bones[bones[i].ParentIndex]; } for (int j = i + 1; j < bones.Length; j++) { if (i == bones[j].ParentIndex) { Bones[i].Children.Add(Bones[j]); } } } foreach (var r in Roots) { SkinBone.CalcRelative(r, Matrix.Identity); } }