private static void AddSkeletalKeyframe(string sequenceName, XElement xmlFrameData) { SkeletalKeyframe newKeyframe = new SkeletalKeyframe(); newKeyframe.DurationInMilliseconds = (int)xmlFrameData.Attribute("duration"); foreach (XElement bone in xmlFrameData.Elements("bonedata")) { SkeletalKeyframe.DataContainer boneKeyframeData = new SkeletalKeyframe.DataContainer(); if (bone.Attribute("rotation") != null) { boneKeyframeData.Rotation = Utility.RectifyAngle(MathHelper.ToRadians((float)bone.Attribute("rotation"))); } if (bone.Attribute("scale") != null) { boneKeyframeData.Scale = (float)bone.Attribute("scale"); } if ((bone.Attribute("offset-x") != null) && (bone.Attribute("offset-y") != null)) { boneKeyframeData.Offset = new Vector2((float)bone.Attribute("offset-x"), (float)bone.Attribute("offset-y")); } if (bone.Element("texture") != null) { if (bone.Element("texture").Attribute("name") != null) { boneKeyframeData.TextureName = bone.Element("texture").Attribute("name").Value; } if ((bone.Attribute("origin-x") != null) && (bone.Attribute("origin-y") != null)) { boneKeyframeData.Origin = new Vector2((float)bone.Attribute("origin-x"), (float)bone.Attribute("origin-y")); } if ((bone.Element("texture").Attribute("frame-x") != null) && (bone.Element("texture").Attribute("frame-y") != null) && (bone.Element("texture").Attribute("frame-width") != null) && (bone.Element("texture").Attribute("frame-height") != null)) { Rectangle frame = new Rectangle((int)bone.Element("texture").Attribute("frame-x"), (int)bone.Element("texture").Attribute("frame-y"), (int)bone.Element("texture").Attribute("frame-width"), (int)bone.Element("texture").Attribute("frame-height")); boneKeyframeData.SourceArea = frame; } } newKeyframe.BoneAnimationData.Add(bone.Attribute("id").Value, boneKeyframeData); } AddKeyframe(sequenceName, newKeyframe); }
private static SkeletalKeyframe[] ReadKeyframes(ContentReader input, SkeletalKeyframe[] existingInstance) { var keyframes = existingInstance; var count = input.ReadInt32(); if (keyframes == null) { keyframes = new SkeletalKeyframe[count]; } for (var i = 0; i < count; i++) { keyframes[i].Bone = input.ReadInt32(); keyframes[i].Time = new TimeSpan(input.ReadInt64()); keyframes[i].Transform = input.ReadMatrix(); //keyframes[i].Transform.M14 = 0; //keyframes[i].Transform.M24 = 0; //keyframes[i].Transform.M34 = 0; //keyframes[i].Transform.M44 = 1; } return(keyframes); }