public AnimationHelperTrack EncodeTrack(Animation.KeyGroup Group, AnimTrackType Type) { AnimationHelperTrack t = new AnimationHelperTrack(); t.TrackType = Type; foreach (Animation.KeyFrame kf in Group.Keys) { AnimationHelperKeyFrame f = new AnimationHelperKeyFrame(); f.Frame = (int)kf.Frame; f.Value = kf.Value; f.Tan = kf.In; t.KeyFrames.Add(f); switch (kf.InterType) { case Animation.InterpolationType.CONSTANT: f.InterpolationType = InterpolationType.Constant; break; case Animation.InterpolationType.HERMITE: f.InterpolationType = InterpolationType.Hermite; break; case Animation.InterpolationType.LINEAR: if (Group.Keys.Count == 1) { f.InterpolationType = InterpolationType.Constant; } else { f.InterpolationType = InterpolationType.Linear; } break; case Animation.InterpolationType.STEP: f.InterpolationType = InterpolationType.Step; break; } } return(t); }
public virtual Animation GetAnimation() { Animation a = new Smash_Forge.Animation(Text); a.FrameCount = (int)DatAnimation.FrameCount; int bid = 0; foreach (DatAnimationNode bone in DatAnimation.Nodes) { Animation.KeyNode node = new Animation.KeyNode("Bone_" + bid++); //Console.WriteLine(node.Text + " " + bone.Tracks.Count); a.Bones.Add(node); node.RotType = Animation.RotationType.EULER; AnimationHelperTrack[] helper; try { helper = AnimationKeyFrameHelper.DecodeKeyFrames(bone); } catch (Exception) { Console.WriteLine("Error Loading animation"); helper = new AnimationHelperTrack[0]; } foreach (AnimationHelperTrack track in helper) { float prevValue = 0; float prevTan = 0; Animation.KeyFrame prevkey = null; Animation.KeyGroup Group = new Animation.KeyGroup(); foreach (AnimationHelperKeyFrame key in track.KeyFrames) { Animation.KeyFrame f = new Animation.KeyFrame(); f.Frame = key.Frame; f.Value = key.Value; f.In = key.Tan; switch (key.InterpolationType) { case InterpolationType.Constant: f.InterType = Animation.InterpolationType.CONSTANT; break; case InterpolationType.Hermite: f.InterType = Animation.InterpolationType.HERMITE; break; case InterpolationType.Linear: f.InterType = Animation.InterpolationType.LINEAR; break; case InterpolationType.Step: f.InterType = Animation.InterpolationType.STEP; break; case InterpolationType.HermiteValue: f.InterType = Animation.InterpolationType.HERMITE; f.In = prevTan; break; case InterpolationType.HermiteCurve: prevkey.Out = key.Tan; continue; } prevValue = key.Value; prevTan = key.Tan; prevkey = f; Group.Keys.Add(f); } switch (track.TrackType) { case AnimTrackType.XPOS: node.XPOS = Group; break; case AnimTrackType.YPOS: node.YPOS = Group; break; case AnimTrackType.ZPOS: node.ZPOS = Group; break; case AnimTrackType.XROT: node.XROT = Group; break; case AnimTrackType.YROT: node.YROT = Group; break; case AnimTrackType.ZROT: node.ZROT = Group; break; case AnimTrackType.XSCA: node.XSCA = Group; break; case AnimTrackType.YSCA: node.YSCA = Group; break; case AnimTrackType.ZSCA: node.ZSCA = Group; break; } } } return(a); }