public AnimationTrack(KEY_Parser.Group track) { InterpolationType = STInterpoaltionType.Hermite; foreach (var keyFrame in track.KeyFrames) { KeyFrames.Add(new STHermiteKeyFrame() { Frame = keyFrame.Frame, Value = keyFrame.Value, TangentIn = keyFrame.InSlope, TangentOut = keyFrame.OutSlope, }); } }
private void WriteGroupText(StringWriter writer, KEY_Parser.Group group, string Name) { writer.WriteLine($" {Name}:"); for (int i = 0; i < group.KeyFrames.Count; i++) { string slopeInfo = ""; if (group.KeyFrames.Count > 1) { slopeInfo = $", InSlope: {group.KeyFrames[i].InSlope}"; } if (group.SlopeFlag > 0) { slopeInfo = $", {slopeInfo}, OutSlope: {group.KeyFrames[i].OutSlope}"; } writer.WriteLine($" - Frame: [{group.KeyFrames[i].Frame}, Value : {group.KeyFrames[i].Value}" + slopeInfo + "]"); } }
public KEY_Parser FromText(string text) { KEY_Parser parser = new KEY_Parser(); List <KEY_Parser.AnimJoint> joints = new List <KEY_Parser.AnimJoint>(); KEY_Parser.AnimJoint activeJoint = null; KEY_Parser.Group activeGroup = null; foreach (var line in text.Split('\n')) { if (line.Contains("FrameCount:")) { parser.FrameCount = ushort.Parse(line.Split(':')[1]); } if (line.Contains("FrameDelay:")) { parser.AnimationDelay = ushort.Parse(line.Split(':')[1]); } if (line.Contains("Flags:")) { parser.Flags = uint.Parse(line.Split(':')[1]); } if (line.Contains("Joint:")) { activeJoint = new KEY_Parser.AnimJoint(); joints.Add(activeJoint); } if (line.Contains("Scale X:")) { activeGroup = new KEY_Parser.Group(); activeJoint.ScaleX = activeGroup; } if (line.Contains("Scale Y:")) { activeGroup = new KEY_Parser.Group(); activeJoint.ScaleY = activeGroup; } if (line.Contains("Scale Z:")) { activeGroup = new KEY_Parser.Group(); activeJoint.ScaleZ = activeGroup; } if (line.Contains("Position X:")) { activeGroup = new KEY_Parser.Group(); activeJoint.PositionX = activeGroup; } if (line.Contains("Position Y:")) { activeGroup = new KEY_Parser.Group(); activeJoint.PositionY = activeGroup; } if (line.Contains("Position Z:")) { activeGroup = new KEY_Parser.Group(); activeJoint.PositionZ = activeGroup; } if (line.Contains("Rotate X:")) { activeGroup = new KEY_Parser.Group(); activeJoint.RotateX = activeGroup; } if (line.Contains("Rotate Y:")) { activeGroup = new KEY_Parser.Group(); activeJoint.RotateY = activeGroup; } if (line.Contains("Rotate Z:")) { activeGroup = new KEY_Parser.Group(); activeJoint.RotateZ = activeGroup; } if (line.Contains("Frame:")) { //Get values from array string value = line.Split('[')[1]; value = value.Replace("[", string.Empty); value = value.Replace("]", string.Empty); // Console.WriteLine($"value {value}"); //Get multiple values in the array string[] values = value.Split(','); KEY_Parser.KeyFrame keyFrame = new KEY_Parser.KeyFrame(); for (int i = 0; i < values.Length; i++) { if (i == 0) { keyFrame.Frame = float.Parse(values[i]); continue; } string val = values[i].Split(':')[1].Replace(" ", string.Empty); if (i == 1) { keyFrame.Value = float.Parse(val); } if (i == 2) { keyFrame.InSlope = float.Parse(val); } if (i == 3) { keyFrame.OutSlope = float.Parse(val); } } activeGroup.KeyFrames.Add(keyFrame); activeGroup.FrameCount = (ushort)activeGroup.KeyFrames.Count; } } parser.AnimJoints = joints.ToArray(); return(parser); }