1
0
mirror of synced 2024-11-28 01:10:51 +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++)
{
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;
}
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;
}
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;
}
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;
}
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;
}
else
{
group6.AddNode(new FMAA(anim, MaterialAnimation.AnimationType.ShaderParam));
group.AddNode(fmaa);
HasMaterialAnim = true;
}
}

View File

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

View File

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

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Windows.Forms;
@ -13,56 +14,39 @@ namespace Bfres.Structs
{
public class FMAA : MaterialAnimation
{
private static readonly string ShaderParamAnimType = "_fsp";
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()
public override AnimationType AnimType
{
if (Parent == null)
return "";
BFRESGroupNode AnimFolder = (BFRESGroupNode)Parent;
switch (AnimFolder.Type)
get
{
case BRESGroupType.TexPatAnim: return TexturePatternAnimType;
case BRESGroupType.ShaderParamAnim: return ShaderParamAnimType;
case BRESGroupType.TexSrtAnim: return TextureSrtAnimType;
case BRESGroupType.ColorAnim: return ColorAnimType;
case BRESGroupType.MatVisAnim: return VisibiltyAnimType;
default:
return "";
if (MaterialAnim != null)
{
string nameType = MaterialAnim.Name.Split('_').Last();
if (MaterialAnim.TextureNames?.Count > 0)
return AnimationType.TexturePattern;
else if (nameMappedTypes.ContainsKey($"_{nameType}"))
return nameMappedTypes[$"_{nameType}"];
else
return AnimationType.ShaderParam;
}
return AnimationType.ShaderParam;
}
}
public static bool IsShaderParamAnimation(string name) {
return name.Contains(ShaderParamAnimType) ||
name.Contains(ShaderParamAnimType2);
}
public static bool IsSRTAnimation(string name){
return name.Contains(TextureSrtAnimType) ||
name.Contains(TextureSrtAnimType2);
}
public static bool IsTexturePattern(string name) {
return name.Contains(TexturePatternAnimType) ||
name.Contains(TexturePatternAnimType2);
}
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);
}
private Dictionary<string, AnimationType> nameMappedTypes = new Dictionary<string, AnimationType>
{
{"_fsp", AnimationType.ShaderParam },
{"_sp", AnimationType.ShaderParam },
{"_ftp", AnimationType.TexturePattern },
{"_tp", AnimationType.TexturePattern },
{"_fts", AnimationType.TextureSrt },
{"_ts", AnimationType.TextureSrt },
{"_fcl", AnimationType.Color },
{"_cl", AnimationType.Color },
{"_fvm", AnimationType.Visibilty },
{"_vm", AnimationType.Visibilty },
};
public override void OnDoubleMouseClick(TreeView treeview)
{
@ -147,6 +131,7 @@ namespace Bfres.Structs
{
MaterialAnim.FrameCount = FrameCount;
MaterialAnim.TextureNames = Textures;
MaterialAnim.Name = Text;
int TexturePatternCurveIndex = 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 MaterialAnim MaterialAnim;
public FMAA()
@ -382,7 +331,7 @@ namespace Bfres.Structs
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)
{
@ -390,7 +339,7 @@ namespace Bfres.Structs
MaterialAnim = anim;
FrameCount = MaterialAnim.FrameCount;
Text = GetString(anim.Name);
Text = anim.Name;
Textures.Clear();
if (anim.TextureNames != null)
@ -414,11 +363,13 @@ namespace Bfres.Structs
paramInfo.Type = AnimationType.ShaderParam;
//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;
else if (anim.Name.Contains(TextureSrtAnimType))
else if (AnimType == 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;
//Get constant anims
@ -731,20 +682,20 @@ namespace Bfres.Structs
if (ext == ".bfmaa")
{
MaterialAnim.Import(FileName);
MaterialAnim.Name = Text + GetTypeExtension();
MaterialAnim.Name = Text;
LoadAnim(MaterialAnim);
}
else if (ext == ".yaml")
{
MaterialAnim = YamlFmaa.FromYaml(FileName);
MaterialAnim.Name = Text + GetTypeExtension();
MaterialAnim.Name = Text;
LoadAnim(MaterialAnim);
}
else if (ext == ".gif" || ext == ".png" || ext == ".apng")
{
BNTX bntx = PluginRuntime.bntxContainers[0];
GifToTexturePatternAnimation anim = new GifToTexturePatternAnimation(FileName, bntx, this);
MaterialAnim.Name = Text + GetTypeExtension();
MaterialAnim.Name = Text;
LoadAnim(MaterialAnim);
}

View File

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