1
0
mirror of synced 2024-11-14 11:07:39 +01:00

Adjust the way material animation types are defined and checked

This commit is contained in:
KillzXGaming 2019-09-22 12:37:20 -04:00
parent e982344d84
commit 8ed6a79b61
5 changed files with 64 additions and 112 deletions

View File

@ -1150,34 +1150,35 @@ namespace FirstPlugin
for (int i = 0; i < resFile.MaterialAnims.Count; i++) for (int i = 0; i < resFile.MaterialAnims.Count; i++)
{ {
var anim = resFile.MaterialAnims[i]; var anim = resFile.MaterialAnims[i];
if (FMAA.IsShaderParamAnimation(anim.Name)) var fmaa = new FMAA(anim);
if (fmaa.AnimType == MaterialAnimation.AnimationType.ShaderParam)
{ {
group.AddNode(new FMAA(anim, MaterialAnimation.AnimationType.ShaderParam)); group.AddNode(fmaa);
HasShaderParamsAnim = true; HasShaderParamsAnim = true;
} }
else if (FMAA.IsSRTAnimation(anim.Name)) else if (fmaa.AnimType == MaterialAnimation.AnimationType.TextureSrt)
{ {
group2.AddNode(new FMAA(anim, MaterialAnimation.AnimationType.TextureSrt)); group2.AddNode(fmaa);
HasTextureSrtAnim = true; HasTextureSrtAnim = true;
} }
else if(FMAA.IsTexturePattern(anim.Name)) else if (fmaa.AnimType == MaterialAnimation.AnimationType.TexturePattern)
{ {
group3.AddNode(new FMAA(anim, MaterialAnimation.AnimationType.TexturePattern)); group3.AddNode(fmaa);
HasTexturePatternAnim = true; HasTexturePatternAnim = true;
} }
else if (FMAA.IsColorAnimation(anim.Name)) else if (fmaa.AnimType == MaterialAnimation.AnimationType.Color)
{ {
group4.AddNode(new FMAA(anim, MaterialAnimation.AnimationType.Color)); group4.AddNode(fmaa);
HasColorAnim = true; HasColorAnim = true;
} }
else if (FMAA.IsVisibiltyAnimation(anim.Name)) else if (fmaa.AnimType == MaterialAnimation.AnimationType.Visibilty)
{ {
group5.AddNode(new FMAA(anim, MaterialAnimation.AnimationType.Visibilty)); group5.AddNode(fmaa);
HasMatVisAnim = true; HasMatVisAnim = true;
} }
else else
{ {
group6.AddNode(new FMAA(anim, MaterialAnimation.AnimationType.ShaderParam)); group.AddNode(fmaa);
HasMaterialAnim = true; HasMaterialAnim = true;
} }
} }

View File

@ -296,7 +296,7 @@ namespace Bfres.Structs
else else
{ {
group = GetOrCreateFolder<FMAA>(type); group = GetOrCreateFolder<FMAA>(type);
FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim());
group.AddNode(fmaa, "NewShaderParamAnim_fsp"); group.AddNode(fmaa, "NewShaderParamAnim_fsp");
} }
@ -317,7 +317,7 @@ namespace Bfres.Structs
else else
{ {
group = GetOrCreateFolder<FMAA>(type); group = GetOrCreateFolder<FMAA>(type);
FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim());
group.AddNode(fmaa, "NewColorAnim_fcl"); group.AddNode(fmaa, "NewColorAnim_fcl");
} }
@ -338,7 +338,7 @@ namespace Bfres.Structs
else else
{ {
group = GetOrCreateFolder<FMAA>(type); group = GetOrCreateFolder<FMAA>(type);
FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim());
group.AddNode(fmaa, "NewTextureTransformAnim_fts"); group.AddNode(fmaa, "NewTextureTransformAnim_fts");
} }
@ -359,7 +359,7 @@ namespace Bfres.Structs
else else
{ {
group = GetOrCreateFolder<FMAA>(type); group = GetOrCreateFolder<FMAA>(type);
FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim());
group.AddNode(fmaa, "NewTexturePatternAnim_ftp"); group.AddNode(fmaa, "NewTexturePatternAnim_ftp");
} }
@ -396,7 +396,7 @@ namespace Bfres.Structs
else else
{ {
group = GetOrCreateFolder<FMAA>(MaterialAnimation.AnimationType.Visibilty); group = GetOrCreateFolder<FMAA>(MaterialAnimation.AnimationType.Visibilty);
FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.Visibilty); FMAA fmaa = new FMAA(new ResNX.MaterialAnim());
group.AddNode(fmaa, "NewMatVisAnim_fvm"); group.AddNode(fmaa, "NewMatVisAnim_fvm");
} }

View File

@ -483,7 +483,7 @@ namespace Bfres.Structs
} }
else else
{ {
FMAA fmaaPrm = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.ShaderParam); FMAA fmaaPrm = new FMAA(new ResNX.MaterialAnim());
fmaaPrm.Text = ResourceName; fmaaPrm.Text = ResourceName;
fmaaPrm.Replace(FileName); fmaaPrm.Replace(FileName);
Nodes.Add(fmaaPrm); Nodes.Add(fmaaPrm);
@ -499,7 +499,7 @@ namespace Bfres.Structs
} }
else else
{ {
FMAA fmaaClr = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.Color); FMAA fmaaClr = new FMAA(new ResNX.MaterialAnim());
fmaaClr.Text = ResourceName; fmaaClr.Text = ResourceName;
fmaaClr.Replace(FileName); fmaaClr.Replace(FileName);
Nodes.Add(fmaaClr); Nodes.Add(fmaaClr);
@ -515,7 +515,7 @@ namespace Bfres.Structs
} }
else else
{ {
FMAA fmaaSrt = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.TextureSrt); FMAA fmaaSrt = new FMAA(new ResNX.MaterialAnim());
fmaaSrt.Text = ResourceName; fmaaSrt.Text = ResourceName;
fmaaSrt.Replace(FileName); fmaaSrt.Replace(FileName);
Nodes.Add(fmaaSrt); Nodes.Add(fmaaSrt);
@ -531,7 +531,7 @@ namespace Bfres.Structs
} }
else else
{ {
FMAA fmaaTxp = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.TexturePattern); FMAA fmaaTxp = new FMAA(new ResNX.MaterialAnim());
fmaaTxp.Text = ResourceName; fmaaTxp.Text = ResourceName;
fmaaTxp.Replace(FileName); fmaaTxp.Replace(FileName);
Nodes.Add(fmaaTxp); Nodes.Add(fmaaTxp);
@ -560,7 +560,7 @@ namespace Bfres.Structs
} }
else else
{ {
FMAA fmaaVis = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.Visibilty); FMAA fmaaVis = new FMAA(new ResNX.MaterialAnim());
fmaaVis.Text = ResourceName; fmaaVis.Text = ResourceName;
fmaaVis.Replace(FileName); fmaaVis.Replace(FileName);
Nodes.Add(fmaaVis); Nodes.Add(fmaaVis);
@ -594,7 +594,7 @@ namespace Bfres.Structs
Nodes.Add(ext); Nodes.Add(ext);
break; break;
case BRESGroupType.MaterialAnim: case BRESGroupType.MaterialAnim:
FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.ShaderParam); FMAA fmaa = new FMAA(new ResNX.MaterialAnim());
fmaa.Replace(FileName); fmaa.Replace(FileName);
Nodes.Add(fmaa); Nodes.Add(fmaa);
break; break;

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Text; using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
@ -13,56 +14,39 @@ namespace Bfres.Structs
{ {
public class FMAA : MaterialAnimation public class FMAA : MaterialAnimation
{ {
private static readonly string ShaderParamAnimType = "_fsp"; public override AnimationType AnimType
private static readonly string ShaderParamAnimType2= "_sp";
private static readonly string TexturePatternAnimType = "_ftp";
private static readonly string TexturePatternAnimType2 = "_tp";
private static readonly string TextureSrtAnimType = "_fts";
private static readonly string TextureSrtAnimType2 = "_ts";
private static readonly string ColorAnimType = "_fcl";
private static readonly string ColorAnimType2 = "_cl";
private static readonly string VisibiltyAnimType = "_fvm";
private static readonly string VisibiltyAnimType2 = "_vm";
public string GetTypeExtension()
{ {
if (Parent == null) get
return "";
BFRESGroupNode AnimFolder = (BFRESGroupNode)Parent;
switch (AnimFolder.Type)
{ {
case BRESGroupType.TexPatAnim: return TexturePatternAnimType; if (MaterialAnim != null)
case BRESGroupType.ShaderParamAnim: return ShaderParamAnimType; {
case BRESGroupType.TexSrtAnim: return TextureSrtAnimType; string nameType = MaterialAnim.Name.Split('_').Last();
case BRESGroupType.ColorAnim: return ColorAnimType;
case BRESGroupType.MatVisAnim: return VisibiltyAnimType; if (MaterialAnim.TextureNames?.Count > 0)
default: return AnimationType.TexturePattern;
return ""; else if (nameMappedTypes.ContainsKey($"_{nameType}"))
return nameMappedTypes[$"_{nameType}"];
else
return AnimationType.ShaderParam;
}
return AnimationType.ShaderParam;
} }
} }
public static bool IsShaderParamAnimation(string name) { private Dictionary<string, AnimationType> nameMappedTypes = new Dictionary<string, AnimationType>
return name.Contains(ShaderParamAnimType) || {
name.Contains(ShaderParamAnimType2); {"_fsp", AnimationType.ShaderParam },
} {"_sp", AnimationType.ShaderParam },
public static bool IsSRTAnimation(string name){ {"_ftp", AnimationType.TexturePattern },
return name.Contains(TextureSrtAnimType) || {"_tp", AnimationType.TexturePattern },
name.Contains(TextureSrtAnimType2); {"_fts", AnimationType.TextureSrt },
} {"_ts", AnimationType.TextureSrt },
public static bool IsTexturePattern(string name) { {"_fcl", AnimationType.Color },
return name.Contains(TexturePatternAnimType) || {"_cl", AnimationType.Color },
name.Contains(TexturePatternAnimType2); {"_fvm", AnimationType.Visibilty },
} {"_vm", AnimationType.Visibilty },
public static bool IsColorAnimation(string name) { };
return name.Contains(ColorAnimType) ||
name.Contains(ColorAnimType2);
}
public static bool IsVisibiltyAnimation(string name) {
return name.Contains(VisibiltyAnimType) ||
name.Contains(VisibiltyAnimType2);
}
public override void OnDoubleMouseClick(TreeView treeview) public override void OnDoubleMouseClick(TreeView treeview)
{ {
@ -147,6 +131,7 @@ namespace Bfres.Structs
{ {
MaterialAnim.FrameCount = FrameCount; MaterialAnim.FrameCount = FrameCount;
MaterialAnim.TextureNames = Textures; MaterialAnim.TextureNames = Textures;
MaterialAnim.Name = Text;
int TexturePatternCurveIndex = 0; int TexturePatternCurveIndex = 0;
int ParamCurveIndex = 0; int ParamCurveIndex = 0;
@ -306,42 +291,6 @@ namespace Bfres.Structs
} }
private string GetString(string Name)
{
StringBuilder builder = new StringBuilder(Name);
builder.Replace(ShaderParamAnimType, "");
builder.Replace(TexturePatternAnimType, "");
builder.Replace(TextureSrtAnimType, "");
builder.Replace(ColorAnimType, "");
builder.Replace(VisibiltyAnimType, "");
return builder.ToString();
}
public string SetName()
{
Text = GetString(Text); //Remove any extension just in case
//Add extension to the end of the string based on type
if (AnimType == AnimationType.Color)
Text += ColorAnimType;
else if (AnimType == AnimationType.ShaderParam)
Text += ShaderParamAnimType;
else if (AnimType == AnimationType.TexturePattern)
Text += TexturePatternAnimType;
else if (AnimType == AnimationType.TextureSrt)
Text += TextureSrtAnimType;
else if (AnimType == AnimationType.Visibilty)
Text += VisibiltyAnimType;
else
Text += ShaderParamAnimType;
MaterialAnim.Name = Text;
return Text;
}
public BFRESRender BFRESRender; public BFRESRender BFRESRender;
public MaterialAnim MaterialAnim; public MaterialAnim MaterialAnim;
public FMAA() public FMAA()
@ -382,7 +331,7 @@ namespace Bfres.Structs
return ((BFRESGroupNode)Parent).GetResFile(); return ((BFRESGroupNode)Parent).GetResFile();
} }
public FMAA(MaterialAnim anim, AnimationType type) { LoadAnim(anim); AnimType = type; } public FMAA(MaterialAnim anim) { LoadAnim(anim); }
private void LoadAnim(MaterialAnim anim) private void LoadAnim(MaterialAnim anim)
{ {
@ -390,7 +339,7 @@ namespace Bfres.Structs
MaterialAnim = anim; MaterialAnim = anim;
FrameCount = MaterialAnim.FrameCount; FrameCount = MaterialAnim.FrameCount;
Text = GetString(anim.Name); Text = anim.Name;
Textures.Clear(); Textures.Clear();
if (anim.TextureNames != null) if (anim.TextureNames != null)
@ -414,11 +363,13 @@ namespace Bfres.Structs
paramInfo.Type = AnimationType.ShaderParam; paramInfo.Type = AnimationType.ShaderParam;
//There is no better way to determine if the param is a color type afaik //There is no better way to determine if the param is a color type afaik
if (anim.Name.Contains(ColorAnimType) || param.Name.Contains("Color") || param.Name.Contains("color") || param.Name == "multi_tex_reg2") if (param.Name.Contains("Color") || param.Name.Contains("color") || param.Name == "multi_tex_reg2")
paramInfo.Type = AnimationType.Color; paramInfo.Type = AnimationType.Color;
else if (anim.Name.Contains(TextureSrtAnimType)) else if (AnimType == AnimationType.TexturePattern)
paramInfo.Type = AnimationType.TexturePattern; paramInfo.Type = AnimationType.TexturePattern;
else if (anim.Name.Contains(ShaderParamAnimType)) else if (AnimType == AnimationType.TextureSrt)
paramInfo.Type = AnimationType.TextureSrt;
else
paramInfo.Type = AnimationType.ShaderParam; paramInfo.Type = AnimationType.ShaderParam;
//Get constant anims //Get constant anims
@ -731,20 +682,20 @@ namespace Bfres.Structs
if (ext == ".bfmaa") if (ext == ".bfmaa")
{ {
MaterialAnim.Import(FileName); MaterialAnim.Import(FileName);
MaterialAnim.Name = Text + GetTypeExtension(); MaterialAnim.Name = Text;
LoadAnim(MaterialAnim); LoadAnim(MaterialAnim);
} }
else if (ext == ".yaml") else if (ext == ".yaml")
{ {
MaterialAnim = YamlFmaa.FromYaml(FileName); MaterialAnim = YamlFmaa.FromYaml(FileName);
MaterialAnim.Name = Text + GetTypeExtension(); MaterialAnim.Name = Text;
LoadAnim(MaterialAnim); LoadAnim(MaterialAnim);
} }
else if (ext == ".gif" || ext == ".png" || ext == ".apng") else if (ext == ".gif" || ext == ".png" || ext == ".apng")
{ {
BNTX bntx = PluginRuntime.bntxContainers[0]; BNTX bntx = PluginRuntime.bntxContainers[0];
GifToTexturePatternAnimation anim = new GifToTexturePatternAnimation(FileName, bntx, this); GifToTexturePatternAnimation anim = new GifToTexturePatternAnimation(FileName, bntx, this);
MaterialAnim.Name = Text + GetTypeExtension(); MaterialAnim.Name = Text;
LoadAnim(MaterialAnim); LoadAnim(MaterialAnim);
} }

View File

@ -10,7 +10,7 @@ namespace Toolbox.Library.Animations
{ {
public class MaterialAnimation : Animation public class MaterialAnimation : Animation
{ {
public AnimationType AnimType; public virtual AnimationType AnimType { get; set; }
public enum AnimationType public enum AnimationType
{ {
ShaderParam, ShaderParam,