2019-07-09 23:50:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-07-14 15:14:15 +02:00
|
|
|
|
using System.IO;
|
2019-07-09 23:50:50 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bfres.Structs;
|
|
|
|
|
using SharpYaml;
|
2019-07-14 15:14:15 +02:00
|
|
|
|
using SharpYaml.Events;
|
2019-07-09 23:50:50 +02:00
|
|
|
|
using SharpYaml.Serialization;
|
2019-07-14 15:14:15 +02:00
|
|
|
|
using SharpYaml.Serialization.Serializers;
|
2019-07-09 23:50:50 +02:00
|
|
|
|
using Syroot.NintenTools.NSW.Bfres;
|
2019-07-14 15:14:15 +02:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2019-07-09 23:50:50 +02:00
|
|
|
|
|
|
|
|
|
namespace FirstPlugin
|
|
|
|
|
{
|
|
|
|
|
public class YamlFmaa
|
|
|
|
|
{
|
|
|
|
|
public class AnimConfig
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Path { get; set; }
|
2019-07-14 03:08:59 +02:00
|
|
|
|
public bool Loop { get; set; }
|
2019-07-09 23:50:50 +02:00
|
|
|
|
public int FrameCount { get; set; }
|
2019-07-14 01:52:04 +02:00
|
|
|
|
|
2019-07-14 15:14:15 +02:00
|
|
|
|
public List<MatAnimConfig> MaterialAnimConfigs { get; set; }
|
2019-07-14 01:52:04 +02:00
|
|
|
|
|
2019-08-27 01:49:44 +02:00
|
|
|
|
public void ToYaml(MaterialAnim materialAnim, FMAA.AnimationType animType)
|
2019-07-14 01:52:04 +02:00
|
|
|
|
{
|
2019-07-14 15:14:15 +02:00
|
|
|
|
MaterialAnimConfigs = new List<MatAnimConfig>();
|
|
|
|
|
|
2019-07-14 01:52:04 +02:00
|
|
|
|
Name = materialAnim.Name;
|
|
|
|
|
Path = materialAnim.Path;
|
|
|
|
|
FrameCount = materialAnim.FrameCount;
|
2019-07-14 03:08:59 +02:00
|
|
|
|
Loop = materialAnim.Loop;
|
2019-07-14 01:52:04 +02:00
|
|
|
|
|
|
|
|
|
foreach (var mat in materialAnim.MaterialAnimDataList)
|
|
|
|
|
{
|
|
|
|
|
MatAnimConfig matConfig = new MatAnimConfig();
|
|
|
|
|
matConfig.Name = mat.Name;
|
2019-07-14 02:20:21 +02:00
|
|
|
|
MaterialAnimConfigs.Add(matConfig);
|
2019-07-14 01:52:04 +02:00
|
|
|
|
|
|
|
|
|
foreach (var paramInfo in mat.ParamAnimInfos)
|
|
|
|
|
{
|
2019-07-14 02:20:21 +02:00
|
|
|
|
ParamInfo paramCfg = new ParamInfo();
|
|
|
|
|
paramCfg.Name = paramInfo.Name;
|
2019-08-26 23:37:12 +02:00
|
|
|
|
paramCfg.IsConstant = paramInfo.ConstantCount != 0;
|
2019-07-14 02:20:21 +02:00
|
|
|
|
matConfig.ParamInfos.Add(paramCfg);
|
2019-07-14 01:52:04 +02:00
|
|
|
|
|
2019-08-26 23:37:12 +02:00
|
|
|
|
if (paramInfo.ConstantCount != 0)
|
|
|
|
|
{
|
|
|
|
|
paramCfg.Constants = new List<ConstantConfig>();
|
|
|
|
|
for (int i = 0; i < paramInfo.ConstantCount; i++)
|
|
|
|
|
{
|
|
|
|
|
AnimConstant constant = mat.Constants[paramInfo.BeginConstant + i];
|
|
|
|
|
ConstantConfig ConstantValue = new ConstantConfig();
|
2019-08-27 01:49:44 +02:00
|
|
|
|
ConstantValue.Offset = ConvertParamOffset(constant.AnimDataOffset, animType);
|
2019-08-27 01:13:08 +02:00
|
|
|
|
ConstantValue.Value = constant.Value;
|
2019-08-26 23:37:12 +02:00
|
|
|
|
|
|
|
|
|
paramCfg.Constants.Add(ConstantValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:20:21 +02:00
|
|
|
|
if (paramInfo.BeginCurve != ushort.MaxValue)
|
|
|
|
|
{
|
2019-08-26 23:37:12 +02:00
|
|
|
|
paramCfg.CurveData = new List<CurveConfig>();
|
2019-07-14 02:20:21 +02:00
|
|
|
|
for (int i = 0; i < paramInfo.IntCurveCount + paramInfo.FloatCurveCount; i++)
|
|
|
|
|
{
|
2019-08-26 23:37:12 +02:00
|
|
|
|
var curve = mat.Curves[(int)paramInfo.BeginCurve + i];
|
|
|
|
|
var CurveCfg = new CurveConfig();
|
2019-08-27 01:49:44 +02:00
|
|
|
|
CurveCfg.Offset = ConvertParamOffset(curve.AnimDataOffset, animType);
|
2019-08-26 23:37:12 +02:00
|
|
|
|
|
|
|
|
|
if (curve.Scale == 0)
|
|
|
|
|
curve.Scale = 1;
|
2019-07-14 02:20:21 +02:00
|
|
|
|
|
2019-08-26 23:37:12 +02:00
|
|
|
|
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);
|
2019-07-14 02:20:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-14 01:52:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var patternInfo in mat.TexturePatternAnimInfos)
|
|
|
|
|
{
|
|
|
|
|
PatternInfo infoCfg = new PatternInfo();
|
|
|
|
|
infoCfg.Name = patternInfo.Name;
|
|
|
|
|
infoCfg.IsConstant = patternInfo.BeginConstant != ushort.MaxValue;
|
2019-07-14 02:20:21 +02:00
|
|
|
|
matConfig.TexturePatternInfos.Add(infoCfg);
|
|
|
|
|
|
2019-07-14 02:32:30 +02:00
|
|
|
|
if (infoCfg.IsConstant)
|
|
|
|
|
{
|
|
|
|
|
infoCfg.ConstantValue = new ConstantTPConfig();
|
|
|
|
|
int Index = (int)mat.Constants[(int)patternInfo.BeginConstant].Value;
|
|
|
|
|
infoCfg.ConstantValue.Texture = materialAnim.TextureNames[Index];
|
|
|
|
|
}
|
2019-07-14 17:48:07 +02:00
|
|
|
|
if (patternInfo.CurveIndex != ushort.MaxValue)
|
2019-07-14 01:52:04 +02:00
|
|
|
|
{
|
|
|
|
|
var curve = mat.Curves[(int)patternInfo.CurveIndex];
|
|
|
|
|
infoCfg.CurveData = new CurveTPConfig();
|
2019-07-14 02:20:21 +02:00
|
|
|
|
|
|
|
|
|
if (curve.Scale == 0)
|
|
|
|
|
curve.Scale = 1;
|
|
|
|
|
|
|
|
|
|
for (int f = 0; f < curve.Frames.Length; f++)
|
|
|
|
|
{
|
|
|
|
|
int frame = (int)curve.Frames[f];
|
|
|
|
|
int Value = (int)curve.Offset + (int)curve.Keys[f, 0] * (int)curve.Scale;
|
|
|
|
|
|
|
|
|
|
infoCfg.CurveData.KeyFrames.Add(frame, materialAnim.TextureNames[Value]);
|
|
|
|
|
}
|
2019-07-14 01:52:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-14 02:54:55 +02:00
|
|
|
|
|
2019-08-27 00:18:48 +02:00
|
|
|
|
private uint ConvertParamOffset(string offset)
|
|
|
|
|
{
|
|
|
|
|
uint val = 0;
|
|
|
|
|
switch (offset)
|
|
|
|
|
{
|
|
|
|
|
case "R": return 0;
|
|
|
|
|
case "G": return 4;
|
|
|
|
|
case "B": return 8;
|
|
|
|
|
case "A": return 12;
|
2019-11-26 22:29:13 +01:00
|
|
|
|
case "Mode": return 0;
|
|
|
|
|
case "Scale X": return 4;
|
|
|
|
|
case "Scale Y": return 8;
|
|
|
|
|
case "Rotate": return 12;
|
2020-01-29 01:04:49 +01:00
|
|
|
|
case "Rotation": return 12;
|
|
|
|
|
case "Rotation X": return 12;
|
|
|
|
|
case "Rotate X": return 12;
|
2020-01-04 00:31:18 +01:00
|
|
|
|
case "Translate X": return 16;
|
|
|
|
|
case "Translate Y": return 20;
|
2019-08-27 00:18:48 +02:00
|
|
|
|
default:
|
2020-01-29 01:04:49 +01:00
|
|
|
|
bool isOffset = uint.TryParse(offset, out val);
|
|
|
|
|
if (!isOffset)
|
|
|
|
|
throw new Exception($"Invalid offset value {offset}");
|
2019-08-27 00:18:48 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-27 01:49:44 +02:00
|
|
|
|
private string ConvertParamOffset(uint offset, FMAA.AnimationType animType)
|
2019-08-26 23:37:12 +02:00
|
|
|
|
{
|
2019-08-27 01:49:44 +02:00
|
|
|
|
if (animType== FMAA.AnimationType.Color)
|
2019-08-26 23:37:12 +02:00
|
|
|
|
{
|
|
|
|
|
switch (offset)
|
|
|
|
|
{
|
|
|
|
|
case 0: return "R";
|
|
|
|
|
case 4: return "G";
|
|
|
|
|
case 8: return "B";
|
|
|
|
|
case 12: return "A";
|
|
|
|
|
default:
|
|
|
|
|
return offset.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-27 01:49:44 +02:00
|
|
|
|
else if (animType == FMAA.AnimationType.TextureSrt)
|
|
|
|
|
{
|
|
|
|
|
switch (offset)
|
|
|
|
|
{
|
2019-11-26 00:04:53 +01:00
|
|
|
|
case 0: return "Mode";
|
|
|
|
|
case 4: return "Scale X";
|
|
|
|
|
case 8: return "Scale Y";
|
|
|
|
|
case 12: return "Rotate";
|
|
|
|
|
case 16: return "Translate X";
|
|
|
|
|
case 20: return "Translate Y";
|
2019-08-27 01:49:44 +02:00
|
|
|
|
default:
|
|
|
|
|
return offset.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-26 23:37:12 +02:00
|
|
|
|
|
|
|
|
|
return offset.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
public MaterialAnim FromYaml()
|
|
|
|
|
{
|
|
|
|
|
MaterialAnim matAnim = new MaterialAnim();
|
|
|
|
|
matAnim.Name = Name;
|
|
|
|
|
matAnim.Path = Path;
|
2019-07-14 03:08:59 +02:00
|
|
|
|
matAnim.Loop = Loop;
|
2019-07-14 02:54:55 +02:00
|
|
|
|
matAnim.FrameCount = FrameCount;
|
|
|
|
|
matAnim.TextureNames = GenerateTextureList();
|
2019-07-14 03:08:59 +02:00
|
|
|
|
matAnim.BindIndices = new ushort[MaterialAnimConfigs.Count];
|
|
|
|
|
for (int i = 0; i < matAnim.BindIndices.Length; i++)
|
|
|
|
|
matAnim.BindIndices[i] = ushort.MaxValue;
|
2019-07-14 02:54:55 +02:00
|
|
|
|
|
2019-07-14 16:55:26 +02:00
|
|
|
|
int ShaderParamCurveIndex = 0;
|
|
|
|
|
int TexturePatternCurveIndex = 0;
|
|
|
|
|
|
2019-07-14 15:48:35 +02:00
|
|
|
|
Console.WriteLine("MaterialAnimConfigs " + MaterialAnimConfigs.Count);
|
2019-07-14 02:54:55 +02:00
|
|
|
|
foreach (var matCfg in MaterialAnimConfigs)
|
|
|
|
|
{
|
|
|
|
|
var matAnimData = new MaterialAnimData();
|
2019-07-14 15:48:35 +02:00
|
|
|
|
matAnimData.Name = matCfg.Name;
|
2019-07-14 02:54:55 +02:00
|
|
|
|
matAnimData.Constants = new List<AnimConstant>();
|
|
|
|
|
matAnimData.Curves = new List<AnimCurve>();
|
2019-07-14 16:55:26 +02:00
|
|
|
|
matAnimData.TexturePatternAnimInfos = new List<TexturePatternAnimInfo>();
|
|
|
|
|
matAnimData.ParamAnimInfos = new List<ParamAnimInfo>();
|
2019-07-14 03:08:59 +02:00
|
|
|
|
matAnimData.BeginVisalConstantIndex = -1;
|
|
|
|
|
matAnimData.ShaderParamCurveIndex = -1;
|
|
|
|
|
matAnimData.VisualConstantIndex = -1;
|
|
|
|
|
matAnimData.TexturePatternCurveIndex = -1;
|
|
|
|
|
matAnimData.VisalCurveIndex = -1;
|
|
|
|
|
matAnim.MaterialAnimDataList.Add(matAnimData);
|
2019-07-14 02:54:55 +02:00
|
|
|
|
|
2019-07-14 17:48:07 +02:00
|
|
|
|
ushort CurveIndex = 0;
|
2019-07-14 15:48:35 +02:00
|
|
|
|
ushort BeginConstantIndex = 0;
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
foreach (var texturePatternCfg in matCfg.TexturePatternInfos)
|
|
|
|
|
{
|
2019-07-14 15:48:35 +02:00
|
|
|
|
TexturePatternAnimInfo patternInfo = new TexturePatternAnimInfo();
|
|
|
|
|
patternInfo.Name = texturePatternCfg.Name;
|
|
|
|
|
matAnimData.TexturePatternAnimInfos.Add(patternInfo);
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
if (texturePatternCfg.IsConstant && texturePatternCfg.ConstantValue != null)
|
|
|
|
|
{
|
2019-07-14 15:48:35 +02:00
|
|
|
|
patternInfo.BeginConstant = BeginConstantIndex++;
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
AnimConstant constant = new AnimConstant();
|
|
|
|
|
constant.AnimDataOffset = 0;
|
|
|
|
|
constant.Value = matAnim.TextureNames.IndexOf(texturePatternCfg.ConstantValue.Texture);
|
2019-07-14 15:32:07 +02:00
|
|
|
|
matAnimData.Constants.Add(constant);
|
|
|
|
|
|
|
|
|
|
matAnimData.VisualConstantIndex = 0;
|
|
|
|
|
matAnimData.BeginVisalConstantIndex = 0;
|
2019-07-14 02:54:55 +02:00
|
|
|
|
}
|
|
|
|
|
else if (texturePatternCfg.CurveData != null)
|
|
|
|
|
{
|
2019-07-14 15:48:35 +02:00
|
|
|
|
patternInfo.CurveIndex = CurveIndex++;
|
|
|
|
|
|
2019-07-14 16:55:26 +02:00
|
|
|
|
matAnimData.TexturePatternCurveIndex = TexturePatternCurveIndex;
|
2019-07-14 03:08:59 +02:00
|
|
|
|
matAnimData.BeginVisalConstantIndex = 0;
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
AnimCurve curve = new AnimCurve();
|
|
|
|
|
matAnimData.Curves.Add(curve);
|
|
|
|
|
|
|
|
|
|
curve.Offset = 0;
|
|
|
|
|
curve.AnimDataOffset = 0;
|
|
|
|
|
curve.Scale = 1;
|
|
|
|
|
curve.CurveType = AnimCurveType.StepInt;
|
|
|
|
|
curve.StartFrame = 0;
|
|
|
|
|
|
|
|
|
|
int FrameCount = texturePatternCfg.CurveData.KeyFrames.Count;
|
|
|
|
|
|
|
|
|
|
curve.Frames = new float[FrameCount];
|
2019-07-14 15:14:15 +02:00
|
|
|
|
curve.Keys = new float[FrameCount, 1];
|
2019-07-14 02:54:55 +02:00
|
|
|
|
|
|
|
|
|
int MaxFrame = 0;
|
|
|
|
|
int MaxIndex = 0;
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
foreach (var KeyFrame in texturePatternCfg.CurveData.KeyFrames)
|
|
|
|
|
{
|
|
|
|
|
int Index = matAnim.TextureNames.IndexOf(KeyFrame.Value);
|
2019-07-14 16:17:55 +02:00
|
|
|
|
Console.WriteLine($"{Index} {KeyFrame.Value}");
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
curve.Frames[i] = KeyFrame.Key;
|
|
|
|
|
curve.Keys[i, 0] = Index;
|
|
|
|
|
|
|
|
|
|
MaxFrame = Math.Max(MaxIndex, KeyFrame.Key);
|
|
|
|
|
MaxIndex = Math.Max(MaxIndex, Index);
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 15:26:18 +02:00
|
|
|
|
curve.EndFrame = curve.Frames.Max();
|
|
|
|
|
|
|
|
|
|
if (curve.Keys.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
curve.Delta = curve.Keys[curve.Keys.Length - 1,0] - curve.Keys[0, 0];
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
if (MaxFrame < byte.MaxValue)
|
|
|
|
|
curve.FrameType = AnimCurveFrameType.Byte;
|
|
|
|
|
else if (MaxFrame < ushort.MaxValue)
|
|
|
|
|
curve.FrameType = AnimCurveFrameType.Decimal10x5;
|
|
|
|
|
else
|
|
|
|
|
curve.FrameType = AnimCurveFrameType.Single;
|
|
|
|
|
|
|
|
|
|
if (MaxIndex < byte.MaxValue)
|
|
|
|
|
curve.KeyType = AnimCurveKeyType.SByte;
|
|
|
|
|
else if (MaxIndex < ushort.MaxValue)
|
|
|
|
|
curve.KeyType = AnimCurveKeyType.Int16;
|
|
|
|
|
else
|
|
|
|
|
curve.KeyType = AnimCurveKeyType.Single;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var paramCfg in matCfg.ParamInfos)
|
|
|
|
|
{
|
2019-08-27 00:18:48 +02:00
|
|
|
|
ParamAnimInfo paramInfo = new ParamAnimInfo();
|
|
|
|
|
paramInfo.Name = paramCfg.Name;
|
|
|
|
|
matAnimData.ParamAnimInfos.Add(paramInfo);
|
|
|
|
|
|
|
|
|
|
if (paramCfg.Constants != null && paramCfg.Constants.Count > 0)
|
|
|
|
|
{
|
2019-08-27 01:11:10 +02:00
|
|
|
|
paramInfo.BeginConstant = BeginConstantIndex;
|
2019-08-27 00:18:48 +02:00
|
|
|
|
paramInfo.ConstantCount = (ushort)paramCfg.Constants.Count;
|
|
|
|
|
|
2019-08-27 01:11:10 +02:00
|
|
|
|
BeginConstantIndex += (ushort)paramCfg.Constants.Count;
|
2019-08-27 00:18:48 +02:00
|
|
|
|
foreach (var constantCfg in paramCfg.Constants)
|
|
|
|
|
{
|
|
|
|
|
AnimConstant constant = new AnimConstant();
|
|
|
|
|
constant.AnimDataOffset = ConvertParamOffset(constantCfg.Offset);
|
|
|
|
|
constant.Value = constantCfg.Value;
|
|
|
|
|
matAnimData.Constants.Add(constant);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-27 02:54:15 +02:00
|
|
|
|
|
2019-08-27 00:18:48 +02:00
|
|
|
|
if (paramCfg.CurveData != null && paramCfg.CurveData.Count > 0)
|
|
|
|
|
{
|
2019-08-27 02:54:15 +02:00
|
|
|
|
matAnimData.ShaderParamCurveIndex = ShaderParamCurveIndex;
|
|
|
|
|
|
2019-08-27 01:11:10 +02:00
|
|
|
|
paramInfo.BeginCurve = CurveIndex;
|
2019-08-27 00:18:48 +02:00
|
|
|
|
paramInfo.FloatCurveCount = (ushort)paramCfg.CurveData.Count;
|
|
|
|
|
|
2019-08-27 01:11:10 +02:00
|
|
|
|
CurveIndex += (ushort)paramCfg.CurveData.Count;
|
2019-08-27 00:18:48 +02:00
|
|
|
|
foreach (var curveCfg in paramCfg.CurveData)
|
|
|
|
|
{
|
|
|
|
|
AnimCurve curve = new AnimCurve();
|
|
|
|
|
matAnimData.Curves.Add(curve);
|
|
|
|
|
curve.Offset = 0;
|
|
|
|
|
curve.AnimDataOffset = ConvertParamOffset(curveCfg.Offset);
|
|
|
|
|
curve.Scale = 1;
|
|
|
|
|
curve.CurveType = AnimCurveType.Linear;
|
|
|
|
|
curve.StartFrame = 0;
|
|
|
|
|
|
|
|
|
|
int MaxFrame = 0;
|
|
|
|
|
float MaxValue = 0;
|
|
|
|
|
|
|
|
|
|
int FrameCount = curveCfg.KeyFrames.Count;
|
|
|
|
|
curve.Frames = new float[FrameCount];
|
|
|
|
|
curve.Keys = new float[FrameCount, 2];
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
var values = curveCfg.KeyFrames.Values.ToList();
|
|
|
|
|
foreach (var KeyFrame in curveCfg.KeyFrames)
|
|
|
|
|
{
|
|
|
|
|
curve.Frames[i] = KeyFrame.Key;
|
|
|
|
|
curve.Keys[i, 0] = KeyFrame.Value;
|
|
|
|
|
|
|
|
|
|
//Calculate delta
|
|
|
|
|
float Delta = 0;
|
|
|
|
|
if (i < values.Count - 1)
|
|
|
|
|
Delta = values[i + 1] - values[i];
|
|
|
|
|
|
|
|
|
|
curve.Keys[i, 1] = Delta;
|
|
|
|
|
|
|
|
|
|
MaxFrame = Math.Max(MaxFrame, KeyFrame.Key);
|
|
|
|
|
MaxValue = Math.Max(MaxValue, KeyFrame.Value);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curve.EndFrame = curve.Frames.Max();
|
|
|
|
|
|
|
|
|
|
if (curve.Keys.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
curve.Delta = values[values.Count - 1] - values[0];
|
|
|
|
|
}
|
2019-07-14 02:54:55 +02:00
|
|
|
|
|
2019-08-27 01:49:44 +02:00
|
|
|
|
curve.KeyType = AnimCurveKeyType.Single;
|
|
|
|
|
curve.FrameType = AnimCurveFrameType.Single;
|
2019-08-27 00:18:48 +02:00
|
|
|
|
|
2019-08-27 01:49:44 +02:00
|
|
|
|
/* if (MaxFrame < byte.MaxValue)
|
2019-08-27 00:18:48 +02:00
|
|
|
|
curve.FrameType = AnimCurveFrameType.Byte;
|
|
|
|
|
else if (MaxFrame < ushort.MaxValue)
|
|
|
|
|
curve.FrameType = AnimCurveFrameType.Decimal10x5;
|
|
|
|
|
else
|
|
|
|
|
curve.FrameType = AnimCurveFrameType.Single;
|
|
|
|
|
|
|
|
|
|
if (MaxValue < byte.MaxValue)
|
|
|
|
|
curve.KeyType = AnimCurveKeyType.SByte;
|
|
|
|
|
else if (MaxValue < ushort.MaxValue)
|
|
|
|
|
curve.KeyType = AnimCurveKeyType.Int16;
|
|
|
|
|
else
|
2019-08-27 01:49:44 +02:00
|
|
|
|
curve.KeyType = AnimCurveKeyType.Single;*/
|
2019-08-27 00:18:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-14 02:54:55 +02:00
|
|
|
|
}
|
2019-07-14 16:55:26 +02:00
|
|
|
|
|
|
|
|
|
TexturePatternCurveIndex += matAnimData.TexturePatternAnimInfos.Where(item => item.CurveIndex != uint.MaxValue).ToList().Count;
|
2019-08-27 02:54:15 +02:00
|
|
|
|
ShaderParamCurveIndex += CurveIndex;
|
2019-07-14 02:54:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 16:55:26 +02:00
|
|
|
|
return matAnim;
|
2019-07-14 02:54:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<string> GenerateTextureList()
|
|
|
|
|
{
|
|
|
|
|
List<string> Textures = new List<string>();
|
|
|
|
|
foreach (var matCfg in MaterialAnimConfigs)
|
|
|
|
|
{
|
|
|
|
|
foreach (var texturePatternCfg in matCfg.TexturePatternInfos)
|
|
|
|
|
{
|
2019-07-14 17:59:54 +02:00
|
|
|
|
if (texturePatternCfg.ConstantValue != null)
|
2019-07-14 17:55:01 +02:00
|
|
|
|
{
|
|
|
|
|
if (!Textures.Contains(texturePatternCfg.ConstantValue.Texture))
|
|
|
|
|
Textures.Add(texturePatternCfg.ConstantValue.Texture);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
if (texturePatternCfg.CurveData == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (var KeyFrame in texturePatternCfg.CurveData.KeyFrames)
|
|
|
|
|
if (!Textures.Contains(KeyFrame.Value))
|
|
|
|
|
Textures.Add(KeyFrame.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Textures;
|
|
|
|
|
}
|
2019-07-14 01:52:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 23:37:12 +02:00
|
|
|
|
public class ConstantConfig
|
|
|
|
|
{
|
|
|
|
|
public string Offset { get; set; }
|
|
|
|
|
public float Value { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:32:30 +02:00
|
|
|
|
public class ConstantTPConfig
|
|
|
|
|
{
|
2019-07-14 15:14:15 +02:00
|
|
|
|
public string Texture { get; set; }
|
2019-07-14 02:32:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 23:37:12 +02:00
|
|
|
|
public class CurveConfig
|
|
|
|
|
{
|
|
|
|
|
public Dictionary<int, float> KeyFrames { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Offset;
|
|
|
|
|
|
|
|
|
|
public CurveConfig()
|
|
|
|
|
{
|
|
|
|
|
KeyFrames = new Dictionary<int, float>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 01:52:04 +02:00
|
|
|
|
public class CurveTPConfig
|
|
|
|
|
{
|
2019-07-14 15:14:15 +02:00
|
|
|
|
public Dictionary<int, string> KeyFrames { get; set; }
|
|
|
|
|
|
|
|
|
|
public CurveTPConfig()
|
|
|
|
|
{
|
|
|
|
|
KeyFrames = new Dictionary<int, string>();
|
|
|
|
|
}
|
2019-07-09 23:50:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MatAnimConfig
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<PatternInfo> TexturePatternInfos { get; set; }
|
|
|
|
|
public List<ParamInfo> ParamInfos { get; set; }
|
2019-07-14 02:20:21 +02:00
|
|
|
|
|
|
|
|
|
public MatAnimConfig()
|
|
|
|
|
{
|
|
|
|
|
TexturePatternInfos = new List<PatternInfo>();
|
|
|
|
|
ParamInfos = new List<ParamInfo>();
|
|
|
|
|
}
|
2019-07-09 23:50:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ParamInfo
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsConstant { get; set; }
|
|
|
|
|
|
2019-08-26 23:37:12 +02:00
|
|
|
|
public List<ConstantConfig> Constants { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<CurveConfig> CurveData { get; set; }
|
2019-07-09 23:50:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PatternInfo
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsConstant { get; set; }
|
2019-07-14 01:52:04 +02:00
|
|
|
|
|
2019-07-14 02:32:30 +02:00
|
|
|
|
public ConstantTPConfig ConstantValue { get; set; }
|
|
|
|
|
|
2019-07-14 01:52:04 +02:00
|
|
|
|
public CurveTPConfig CurveData { get; set; }
|
2019-07-09 23:50:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:54:55 +02:00
|
|
|
|
public static MaterialAnim FromYaml(string Name)
|
|
|
|
|
{
|
2019-07-14 03:08:59 +02:00
|
|
|
|
var serializerSettings = new SerializerSettings()
|
|
|
|
|
{
|
2019-07-14 15:14:15 +02:00
|
|
|
|
// EmitTags = false
|
2019-07-14 03:08:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
serializerSettings.DefaultStyle = YamlStyle.Any;
|
|
|
|
|
serializerSettings.ComparerForKeySorting = null;
|
2019-07-14 15:14:15 +02:00
|
|
|
|
serializerSettings.RegisterTagMapping("AnimConfig", typeof(AnimConfig));
|
2019-07-14 03:08:59 +02:00
|
|
|
|
|
2019-07-14 15:14:15 +02:00
|
|
|
|
var serializer = new Serializer( serializerSettings);
|
2019-07-14 15:48:35 +02:00
|
|
|
|
AnimConfig config = serializer.Deserialize<AnimConfig>(File.ReadAllText(Name));
|
2019-07-14 02:54:55 +02:00
|
|
|
|
|
2019-07-14 15:48:35 +02:00
|
|
|
|
return config.FromYaml();
|
2019-07-14 02:54:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 01:49:44 +02:00
|
|
|
|
public static string ToYaml(string Name, MaterialAnim MatAnim, FMAA.AnimationType animType)
|
2019-07-09 23:50:50 +02:00
|
|
|
|
{
|
|
|
|
|
var serializerSettings = new SerializerSettings()
|
|
|
|
|
{
|
2019-07-14 15:14:15 +02:00
|
|
|
|
// EmitTags = false
|
2019-07-09 23:50:50 +02:00
|
|
|
|
};
|
|
|
|
|
|
2019-07-14 02:32:30 +02:00
|
|
|
|
serializerSettings.DefaultStyle = YamlStyle.Any;
|
|
|
|
|
serializerSettings.ComparerForKeySorting = null;
|
2019-07-14 15:14:15 +02:00
|
|
|
|
serializerSettings.RegisterTagMapping("AnimConfig", typeof(AnimConfig));
|
2019-07-14 02:32:30 +02:00
|
|
|
|
|
2019-07-14 15:14:15 +02:00
|
|
|
|
var config = new AnimConfig();
|
2019-08-27 01:49:44 +02:00
|
|
|
|
config.ToYaml(MatAnim, animType);
|
2019-07-09 23:50:50 +02:00
|
|
|
|
|
|
|
|
|
var serializer = new Serializer(serializerSettings);
|
2019-07-14 15:14:15 +02:00
|
|
|
|
string yaml = serializer.Serialize(config, typeof(AnimConfig));
|
|
|
|
|
|
|
|
|
|
return yaml;
|
2019-07-14 01:52:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetConfig()
|
|
|
|
|
{
|
|
|
|
|
|
2019-07-09 23:50:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|