From 372f0b3c43875ed0db5c57d05a71f3bfd19c4ee5 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Mon, 26 Aug 2019 17:37:12 -0400 Subject: [PATCH] Export switch shader param data as yaml --- .../BFRES/Bfres Structs/SubFiles/FMAA.cs | 2 +- .../BFRES/Bfres Structs/SubFiles/FTXP.cs | 2 +- File_Format_Library/YAML/YamlFmaa.cs | 77 +++++++++++++++++-- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs index 4d0de61c..41e82406 100644 --- a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs +++ b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs @@ -720,7 +720,7 @@ namespace Bfres.Structs } else if (ext == ".yaml") { - System.IO.File.WriteAllText(FileName, YamlFmaa.ToYaml(FileName, MaterialAnim)); + System.IO.File.WriteAllText(FileName, YamlFmaa.ToYaml(FileName, MaterialAnim, AnimType == AnimationType.Color)); } } public override void Replace(string FileName) diff --git a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs index 05412db1..6c3d9469 100644 --- a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs +++ b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs @@ -240,7 +240,7 @@ namespace Bfres.Structs } else if (ext == ".yaml") { - var yaml = YamlFmaa.ToYaml(FileName, BfresPlatformConverter.FTXPConvertWiiUToSwitch(TexPatternAnim)); + var yaml = YamlFmaa.ToYaml(FileName, BfresPlatformConverter.FTXPConvertWiiUToSwitch(TexPatternAnim), false); System.IO.File.WriteAllText(FileName, yaml); } } diff --git a/File_Format_Library/YAML/YamlFmaa.cs b/File_Format_Library/YAML/YamlFmaa.cs index 9b414111..1e43597a 100644 --- a/File_Format_Library/YAML/YamlFmaa.cs +++ b/File_Format_Library/YAML/YamlFmaa.cs @@ -25,7 +25,7 @@ namespace FirstPlugin public List MaterialAnimConfigs { get; set; } - public void ToYaml(MaterialAnim materialAnim) + public void ToYaml(MaterialAnim materialAnim, bool isColorParam) { MaterialAnimConfigs = new List(); @@ -44,15 +44,42 @@ namespace FirstPlugin { ParamInfo paramCfg = new ParamInfo(); paramCfg.Name = paramInfo.Name; - paramCfg.IsConstant = paramInfo.BeginConstant != ushort.MaxValue; + paramCfg.IsConstant = paramInfo.ConstantCount != 0; matConfig.ParamInfos.Add(paramCfg); + if (paramInfo.ConstantCount != 0) + { + paramCfg.Constants = new List(); + for (int i = 0; i < paramInfo.ConstantCount; i++) + { + AnimConstant constant = mat.Constants[paramInfo.BeginConstant + i]; + ConstantConfig ConstantValue = new ConstantConfig(); + ConstantValue.Offset = ConvertParamOffset(constant.AnimDataOffset, isColorParam); + ConstantValue.Value = constant.AnimDataOffset; + + paramCfg.Constants.Add(ConstantValue); + } + } + if (paramInfo.BeginCurve != ushort.MaxValue) { - var curve = mat.Curves[(int)paramInfo.BeginCurve]; + paramCfg.CurveData = new List(); for (int i = 0; i < paramInfo.IntCurveCount + paramInfo.FloatCurveCount; i++) { + var curve = mat.Curves[(int)paramInfo.BeginCurve + i]; + var CurveCfg = new CurveConfig(); + if (curve.Scale == 0) + curve.Scale = 1; + + for (int f = 0; f < curve.Frames.Length; f++) + { + int frame = (int)curve.Frames[f]; + float Value = curve.Offset + curve.Keys[f, 0] * curve.Scale; + CurveCfg.KeyFrames.Add(frame, Value); + } + + paramCfg.CurveData.Add(CurveCfg); } } } @@ -90,6 +117,24 @@ namespace FirstPlugin } } + private string ConvertParamOffset(uint offset, bool isColorParam) + { + if (isColorParam) + { + switch (offset) + { + case 0: return "R"; + case 4: return "G"; + case 8: return "B"; + case 12: return "A"; + default: + return offset.ToString(); + } + } + + return offset.ToString(); + } + public MaterialAnim FromYaml() { MaterialAnim matAnim = new MaterialAnim(); @@ -242,11 +287,29 @@ namespace FirstPlugin } } + public class ConstantConfig + { + public string Offset { get; set; } + public float Value { get; set; } + } + public class ConstantTPConfig { public string Texture { get; set; } } + public class CurveConfig + { + public Dictionary KeyFrames { get; set; } + + public string Offset; + + public CurveConfig() + { + KeyFrames = new Dictionary(); + } + } + public class CurveTPConfig { public Dictionary KeyFrames { get; set; } @@ -277,7 +340,9 @@ namespace FirstPlugin public bool IsConstant { get; set; } - public AnimCurve Curve { get; set; } + public List Constants { get; set; } + + public List CurveData { get; set; } } public class PatternInfo @@ -308,7 +373,7 @@ namespace FirstPlugin return config.FromYaml(); } - public static string ToYaml(string Name, MaterialAnim MatAnim) + public static string ToYaml(string Name, MaterialAnim MatAnim, bool isColorParam) { var serializerSettings = new SerializerSettings() { @@ -320,7 +385,7 @@ namespace FirstPlugin serializerSettings.RegisterTagMapping("AnimConfig", typeof(AnimConfig)); var config = new AnimConfig(); - config.ToYaml(MatAnim); + config.ToYaml(MatAnim, isColorParam); var serializer = new Serializer(serializerSettings); string yaml = serializer.Serialize(config, typeof(AnimConfig));