public FlverBoneInfo(HkxBoneInfo copyFromHkx, List <HkxBoneInfo> hkxBoneList, List <FlverBoneInfo> flverBoneList) { ApplyHkxBoneProperties(copyFromHkx, hkxBoneList, flverBoneList); BoundingBoxPrim = new DbgPrimWireBox(Transform.Default, Vector3.One * -0.01f, Vector3.One * 0.01f, DBG.COLOR_FLVER_BONE_BBOX) { Category = DbgPrimCategory.FlverBoneBoundingBox, }; SpawnPrinter.AppendLine(Name, DBG.COLOR_FLVER_BONE); }
public void ApplyHkxBoneProperties(HkxBoneInfo copyFromHkx, List <HkxBoneInfo> hkxBoneList, List <FlverBoneInfo> flverBoneList) { Name = copyFromHkx.Name; ParentReferenceMatrix = copyFromHkx.ReferenceMatrix * Matrix.Invert(copyFromHkx.RelativeReferenceMatrix); ReferenceMatrix = copyFromHkx.ReferenceMatrix; CurrentMatrix = ReferenceMatrix; HkxBoneIndex = hkxBoneList.IndexOf(copyFromHkx); IsNub = false; ChildBones.Clear(); foreach (var ci in copyFromHkx.ChildIndices) { if (ci >= 0 && ci < hkxBoneList.Count) { var matchingFlverChildBone = flverBoneList.FirstOrDefault(b => b.Name == hkxBoneList[ci].Name); if (matchingFlverChildBone != null && !ChildBones.Contains(matchingFlverChildBone)) { ChildBones.Add(matchingFlverChildBone); } } } }
public void LoadHKXSkeleton(HKX.HKASkeleton skeleton) { OriginalHavokSkeleton = skeleton; HkxSkeleton.Clear(); TopLevelHkxBoneIndices.Clear(); for (int i = 0; i < skeleton.Bones.Size; i++) { var newHkxBone = new HkxBoneInfo(); newHkxBone.Name = skeleton.Bones[i].Name.GetString(); newHkxBone.ParentIndex = skeleton.ParentIndices[i].data; newHkxBone.RelativeReferenceTransform = new NewBlendableTransform() { Translation = new System.Numerics.Vector3( skeleton.Transforms[i].Position.Vector.X, skeleton.Transforms[i].Position.Vector.Y, skeleton.Transforms[i].Position.Vector.Z), Rotation = new System.Numerics.Quaternion( skeleton.Transforms[i].Rotation.Vector.X, skeleton.Transforms[i].Rotation.Vector.Y, skeleton.Transforms[i].Rotation.Vector.Z, skeleton.Transforms[i].Rotation.Vector.W), Scale = new System.Numerics.Vector3( skeleton.Transforms[i].Scale.Vector.X, skeleton.Transforms[i].Scale.Vector.Y, skeleton.Transforms[i].Scale.Vector.Z), }; newHkxBone.RelativeReferenceMatrix = Matrix.CreateScale(new Vector3( skeleton.Transforms[i].Scale.Vector.X, skeleton.Transforms[i].Scale.Vector.Y, skeleton.Transforms[i].Scale.Vector.Z)) * Matrix.CreateFromQuaternion(Quaternion.Normalize(new Quaternion( skeleton.Transforms[i].Rotation.Vector.X, skeleton.Transforms[i].Rotation.Vector.Y, skeleton.Transforms[i].Rotation.Vector.Z, skeleton.Transforms[i].Rotation.Vector.W))) * Matrix.CreateTranslation(new Vector3( skeleton.Transforms[i].Position.Vector.X, skeleton.Transforms[i].Position.Vector.Y, skeleton.Transforms[i].Position.Vector.Z)); HkxSkeleton.Add(newHkxBone); } void GetAbsoluteReferenceMatrix(int i) { Matrix result = Matrix.Identity; int j = i; do { result = HkxSkeleton[j].RelativeReferenceMatrix * result; j = HkxSkeleton[j].ParentIndex; }while (j >= 0); HkxSkeleton[i].ReferenceMatrix = result; HkxSkeleton[i].ReferenceMatrixRootBoneIndex = j; } for (int i = 0; i < HkxSkeleton.Count; i++) { if (HkxSkeleton[i].ParentIndex < 0) { TopLevelHkxBoneIndices.Add(i); } for (int j = 0; j < HkxSkeleton.Count; j++) { if (HkxSkeleton[j].ParentIndex == i) { HkxSkeleton[i].ChildIndices.Add(j); } } GetAbsoluteReferenceMatrix(i); } }
public void LoadHKXSkeleton(HKX.HKASkeleton skeleton) { OriginalHavokSkeleton = skeleton; HkxSkeleton.Clear(); for (int i = 0; i < skeleton.Bones.Size; i++) { var newHkxBone = new HkxBoneInfo(); newHkxBone.Name = skeleton.Bones[i].Name.GetString(); newHkxBone.ParentIndex = skeleton.ParentIndices[i].data; newHkxBone.RelativeReferenceMatrix = Matrix.CreateScale(new Vector3( skeleton.Transforms[i].Scale.Vector.X, skeleton.Transforms[i].Scale.Vector.Y, skeleton.Transforms[i].Scale.Vector.Z)) * Matrix.CreateFromQuaternion(new Quaternion( skeleton.Transforms[i].Rotation.Vector.X, skeleton.Transforms[i].Rotation.Vector.Y, skeleton.Transforms[i].Rotation.Vector.Z, skeleton.Transforms[i].Rotation.Vector.W)) * Matrix.CreateTranslation(new Vector3( skeleton.Transforms[i].Position.Vector.X, skeleton.Transforms[i].Position.Vector.Y, skeleton.Transforms[i].Position.Vector.Z)); for (int j = 0; j < FlverSkeleton.Count; j++) { if (FlverSkeleton[j].Name == newHkxBone.Name) { FlverSkeleton[j].HkxBoneIndex = i; newHkxBone.FlverBoneIndex = j; break; } } HkxSkeleton.Add(newHkxBone); } Matrix GetAbsoluteReferenceMatrix(int i) { Matrix result = Matrix.Identity; do { result *= HkxSkeleton[i].RelativeReferenceMatrix; i = HkxSkeleton[i].ParentIndex; }while (i >= 0); return(result); } var flverDeadBonesToApplyHkxChildrenTo = new Dictionary <int, int>(); for (int i = 0; i < HkxSkeleton.Count; i++) { HkxSkeleton[i].ReferenceMatrix = GetAbsoluteReferenceMatrix(i); for (int j = 0; j < HkxSkeleton.Count; j++) { if (HkxSkeleton[j].ParentIndex == i) { HkxSkeleton[i].ChildIndices.Add(j); } } if (HkxSkeleton[i].ParentIndex < 0) { RootBoneIndices.Add(i); } if (HkxSkeleton[i].FlverBoneIndex == -1) { HkxSkeleton[i].FlverBoneIndex = FlverSkeleton.Count; var newFlverBone = new FlverBoneInfo(HkxSkeleton[i], HkxSkeleton, FlverSkeleton); FlverSkeleton.Add(newFlverBone); if (!flverDeadBonesToApplyHkxChildrenTo.ContainsKey(HkxSkeleton[i].FlverBoneIndex)) { flverDeadBonesToApplyHkxChildrenTo.Add(HkxSkeleton[i].FlverBoneIndex, i); } } else if (FlverSkeleton[HkxSkeleton[i].FlverBoneIndex].IsNub) { FlverSkeleton[HkxSkeleton[i].FlverBoneIndex].ApplyHkxBoneProperties(HkxSkeleton[i], HkxSkeleton, FlverSkeleton); if (!flverDeadBonesToApplyHkxChildrenTo.ContainsKey(HkxSkeleton[i].FlverBoneIndex)) { flverDeadBonesToApplyHkxChildrenTo.Add(HkxSkeleton[i].FlverBoneIndex, i); } } foreach (var kvp in flverDeadBonesToApplyHkxChildrenTo) { FlverSkeleton[kvp.Key].ChildBones.Clear(); var copyFromHkx = HkxSkeleton[kvp.Value]; foreach (var ci in copyFromHkx.ChildIndices) { if (ci >= 0 && ci < HkxSkeleton.Count) { var matchingFlverChildBone = FlverSkeleton.FirstOrDefault(b => b.Name == HkxSkeleton[ci].Name); if (matchingFlverChildBone != null && !FlverSkeleton[kvp.Key].ChildBones.Contains(matchingFlverChildBone)) { FlverSkeleton[kvp.Key].ChildBones.Add(matchingFlverChildBone); } } } if (HkxSkeleton[kvp.Value].ParentIndex >= 0 && HkxSkeleton[kvp.Value].ParentIndex < HkxSkeleton.Count) { var matchingFlverParentBone = FlverSkeleton.FirstOrDefault(b => b.Name == HkxSkeleton[HkxSkeleton[kvp.Value].ParentIndex].Name); if (matchingFlverParentBone != null && !matchingFlverParentBone.ChildBones.Contains(FlverSkeleton[kvp.Key])) { matchingFlverParentBone.ChildBones.Add(FlverSkeleton[kvp.Key]); } } } } }
public void LoadHKXSkeleton(HKX.HKASkeleton skeleton) { OriginalHavokSkeleton = skeleton; HkxSkeleton.Clear(); for (int i = 0; i < skeleton.Bones.Size; i++) { var newHkxBone = new HkxBoneInfo(); newHkxBone.Name = skeleton.Bones[i].Name.GetString(); newHkxBone.ParentIndex = skeleton.ParentIndices[i].data; newHkxBone.RelativeReferenceMatrix = Matrix.CreateScale(new Vector3( skeleton.Transforms[i].Scale.Vector.X, skeleton.Transforms[i].Scale.Vector.Y, skeleton.Transforms[i].Scale.Vector.Z)) * Matrix.CreateFromQuaternion(new Quaternion( skeleton.Transforms[i].Rotation.Vector.X, skeleton.Transforms[i].Rotation.Vector.Y, skeleton.Transforms[i].Rotation.Vector.Z, skeleton.Transforms[i].Rotation.Vector.W)) * Matrix.CreateTranslation(new Vector3( skeleton.Transforms[i].Position.Vector.X, skeleton.Transforms[i].Position.Vector.Y, skeleton.Transforms[i].Position.Vector.Z)); for (int j = 0; j < FlverSkeleton.Count; j++) { if (FlverSkeleton[j].Name == newHkxBone.Name) { FlverSkeleton[j].HkxBoneIndex = i; newHkxBone.FlverBoneIndex = j; break; } } HkxSkeleton.Add(newHkxBone); } Matrix GetAbsoluteReferenceMatrix(int i) { Matrix result = Matrix.Identity; do { result *= HkxSkeleton[i].RelativeReferenceMatrix; i = HkxSkeleton[i].ParentIndex; }while (i >= 0); return(result); } for (int i = 0; i < HkxSkeleton.Count; i++) { HkxSkeleton[i].ReferenceMatrix = GetAbsoluteReferenceMatrix(i); for (int j = 0; j < HkxSkeleton.Count; j++) { if (HkxSkeleton[j].ParentIndex == i) { HkxSkeleton[i].ChildIndices.Add(j); } } if (HkxSkeleton[i].ParentIndex < 0) { RootBoneIndices.Add(i); } } }