public static AnimationFile ExtractPartOfSkeleton(GameSkeleton skeleton, string skeletonName, int[] bones) { // Header var animFile = new AnimationFile(); animFile.Header.SkeletonName = skeletonName; animFile.Header.AnimationTotalPlayTimeInSec = 0.1f; animFile.Bones = new AnimationFile.BoneInfo[bones.Length]; CreateBoneTable(skeleton, bones, ref animFile); // Create the keyframe animFile.DynamicFrames = new List <AnimationFile.Frame>(); var frame = new AnimationFile.Frame(); animFile.DynamicFrames.Add(frame); // Populate the keyframe for (int i = 0; i < bones.Length; i++) { var originalBoneIndex = bones[i]; if (i == 0) { var worldTrans = skeleton.GetWorldTransform(originalBoneIndex); var res = worldTrans.Decompose(out Vector3 scale, out var rot, out var trans); frame.Transforms.Add(new RmvVector3(trans.X, trans.Y, trans.Z)); frame.Quaternion.Add(new RmvVector4(rot.X, rot.Y, rot.Z, rot.W)); } else { var trans = skeleton.Translation[originalBoneIndex]; var rot = skeleton.Rotation[originalBoneIndex]; frame.Transforms.Add(new RmvVector3(trans.X, trans.Y, trans.Z)); frame.Quaternion.Add(new RmvVector4(rot.X, rot.Y, rot.Z, rot.W)); } } return(animFile); //var sample = AnimationSampler.Sample(0, 0, skeleton, new List<AnimationClip>() { animation }, true, true); }
KeyFrame CreateKeyFrame(AnimationFile.Frame frame) { var output = new KeyFrame(); foreach (var translation in frame.Transforms) { output.Position.Add(new Vector3(translation.X, translation.Y, translation.Z)); } foreach (var rotation in frame.Quaternion) { output.Rotation.Add(new Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W)); } foreach (var rotation in frame.Quaternion) { output.Scale.Add(Vector3.One); } return(output); }