public static void RebuildFigaTree(string path, string outpath) { HSDRawFile file = new HSDRawFile(path); var oldTree = file.Roots[0].Data as HSD_FigaTree; HSDRawFile newFile = new HSDRawFile(); HSD_FigaTree newTree = new HSD_FigaTree(); newTree.FrameCount = oldTree.FrameCount; newFile.Roots = new List <HSDRootNode>(); newFile.Roots.Add(new HSDRootNode() { Name = file.Roots[0].Name, Data = newTree }); var newtracks = new List <FigaTreeNode>(); foreach (var tracks in oldTree.Nodes) { var newt = new List <HSD_Track>(); foreach (var track in tracks.Tracks) { HSD_Track newtrack = new HSD_Track(); newtrack.FOBJ = FOBJFrameEncoder.EncodeFrames(track.GetKeys(), track.FOBJ.JointTrackType); newt.Add(newtrack); } newtracks.Add(new FigaTreeNode() { Tracks = newt }); } newTree.Nodes = newtracks; newFile.Save(outpath); }
/// <summary> /// /// </summary> /// <param name="track"></param> /// <returns></returns> private static HSD_FOBJ EncodeFOBJ(SBTransformTrack track) { List <FOBJKey> keys = new List <FOBJKey>(); SBAnimKey <float> prevKey = null; var constant = true; var v = track.Keys.Keys.Count > 0 ? track.Keys.Keys[0].Value : 0; foreach (var key in track.Keys.Keys) { if (key.Value != v) { constant = false; break; } } if (constant) { keys.Add(new FOBJKey() { Frame = 0, Value = v, InterpolationType = GXInterpolationType.HSD_A_OP_CON }); } else { for (int i = 0; i < track.Keys.Keys.Count; i++) { var key = track.Keys.Keys[i]; if (i > 0 && track.Keys.Keys[i - 1].InTan != track.Keys.Keys[i - 1].OutTan) { keys.Add(new FOBJKey() { Frame = key.Frame, Tan = track.Keys.Keys[i - 1].OutTan, InterpolationType = GXInterpolationType.HSD_A_OP_SLP }); } if (key.InterpolationType == Scenes.Animation.InterpolationType.Hermite && prevKey != null && prevKey.InterpolationType == key.InterpolationType && prevKey.InTan == key.InTan && prevKey.OutTan == key.OutTan) { keys.Add(new FOBJKey() { Frame = key.Frame, Value = key.Value, InterpolationType = GXInterpolationType.HSD_A_OP_SPL0 }); } else { keys.Add(new FOBJKey() { Frame = key.Frame, Value = key.Value, Tan = key.InTan, InterpolationType = ToGXInterpolation(key.InterpolationType) }); } prevKey = key; } } return(FOBJFrameEncoder.EncodeFrames(keys, ToGXTrackType(track.Type))); }