1
0
mirror of synced 2025-02-20 20:51:35 +01:00

Some fixes. Some progress on converting switch/wii u texture binaries

This commit is contained in:
KillzXGaming 2019-06-02 14:08:10 -04:00
parent 9d7688cbf6
commit 54f6fbb227
12 changed files with 294 additions and 5 deletions

Binary file not shown.

View File

@ -5,6 +5,8 @@ using System.Text;
using System.Threading.Tasks;
using ResU = Syroot.NintenTools.Bfres;
using ResNX = Syroot.NintenTools.NSW.Bfres;
using ResGFXBNTX = Syroot.NintenTools.NSW.Bntx.GFX;
using Syroot.NintenTools.NSW.Bntx;
namespace FirstPlugin
{
@ -14,6 +16,11 @@ namespace FirstPlugin
{
ResNX.ResFile resFile = new ResNX.ResFile();
foreach (var model in resFileU.Models)
{
}
return resFile;
}
@ -24,8 +31,106 @@ namespace FirstPlugin
return resFile;
}
public static Texture WiiUToSwicthBNTXTexture(ResU.Texture textureU)
{
Texture texture = new Texture();
texture.Height = textureU.Height;
texture.Width = textureU.Width;
texture.Format = ConvertGX2ToSwitchFormat(textureU.Format);
texture.Alignment = (int)textureU.Alignment;
texture.ArrayLength = textureU.ArrayLength;
texture.ChannelRed = ConvertWiiUToBNTXChannel(textureU.CompSelR);
texture.ChannelGreen = ConvertWiiUToBNTXChannel(textureU.CompSelG);
texture.ChannelBlue = ConvertWiiUToBNTXChannel(textureU.CompSelB);
texture.ChannelAlpha = ConvertWiiUToBNTXChannel(textureU.CompSelA);
texture.MipCount = textureU.MipCount == 0 ? 1 : texture.MipCount;
texture.Swizzle = 0;
return texture;
}
//Todo. Bake sizes are altered in switch somewhat, although mostly all animations should be fine
public static ResNX.MaterialAnim FVISConvertWiiUToSwitch(ResU.VisibilityAnim VisualAnim)
{
ResNX.MaterialAnim matAnim = new ResNX.MaterialAnim();
matAnim.Name = VisualAnim.Name;
matAnim.Path = VisualAnim.Path;
matAnim.FrameCount = VisualAnim.FrameCount;
matAnim.BindIndices = VisualAnim.BindIndices;
matAnim.BakedSize = VisualAnim.BakedSize;
matAnim.Loop = VisualAnim.Flags.HasFlag(ResU.TexPatternAnimFlags.Looping);
int CurveIndex = 0;
for (int m = 0; m < VisualAnim.Names.Count; m++)
{
ResNX.MaterialAnimData matAnimData = new ResNX.MaterialAnimData();
matAnimData.Name = VisualAnim.Names[m];
}
matAnim.UserData = ConvertUserDataWiiU2Switch(VisualAnim.UserData);
return matAnim;
}
public static ResNX.MaterialAnim FSHUConvertWiiUToSwitch(ResU.ShaderParamAnim ShaderAnim)
{
ResNX.MaterialAnim matAnim = new ResNX.MaterialAnim();
matAnim.Name = ShaderAnim.Name;
matAnim.Path = ShaderAnim.Path;
matAnim.FrameCount = ShaderAnim.FrameCount;
matAnim.BindIndices = ShaderAnim.BindIndices;
matAnim.BakedSize = ShaderAnim.BakedSize;
matAnim.Loop = ShaderAnim.Flags.HasFlag(ResU.TexPatternAnimFlags.Looping);
int CurveIndex = 0;
for (int m = 0; m < ShaderAnim.ShaderParamMatAnims.Count; m++)
{
ResNX.MaterialAnimData matAnimData = new ResNX.MaterialAnimData();
matAnimData.Name = ShaderAnim.ShaderParamMatAnims[m].Name;
foreach (var paramU in ShaderAnim.ShaderParamMatAnims[m].ParamAnimInfos)
{
ResNX.ParamAnimInfo animInfo = new ResNX.ParamAnimInfo();
animInfo.Name = paramU.Name;
animInfo.BeginCurve = paramU.BeginCurve;
animInfo.BeginConstant = paramU.BeginConstant;
animInfo.ConstantCount = paramU.ConstantCount;
animInfo.FloatCurveCount = paramU.FloatCurveCount;
animInfo.IntCurveCount = paramU.IntCurveCount;
animInfo.SubBindIndex = paramU.SubBindIndex;
matAnimData.ParamAnimInfos.Add(animInfo);
}
if (ShaderAnim.ShaderParamMatAnims[m].Curves.Count == 0)
{
foreach (var constant in ShaderAnim.ShaderParamMatAnims[m].Constants)
{
//Add base values as constants
matAnimData.Constants.Add(new ResNX.AnimConstant()
{
Value = (float)constant.Value,
AnimDataOffset = constant.AnimDataOffset,
});
}
}
else
{
matAnimData.ShaderParamCurveIndex = CurveIndex++;
matAnimData.BeginVisalConstantIndex = 0;
matAnimData.Curves = ConvertAnimCurveWiiUToSwitch(ShaderAnim.ShaderParamMatAnims[m].Curves);
}
matAnim.MaterialAnimDataList.Add(matAnimData);
}
matAnim.UserData = ConvertUserDataWiiU2Switch(ShaderAnim.UserData);
return matAnim;
}
public static ResNX.MaterialAnim FTXPConvertWiiUToSwitch(ResU.TexPatternAnim texPatternAnim)
{
//Different versions use different lists
@ -53,7 +158,6 @@ namespace FirstPlugin
{
ResNX.MaterialAnimData matAnimData = new ResNX.MaterialAnimData();
matAnimData.Name = texPatternAnim.TexPatternMatAnims[m].Name;
matAnimData.TexturePatternCurveIndex = 0;
foreach (var patternInfoU in texPatternAnim.TexPatternMatAnims[m].PatternAnimInfos)
{
@ -78,7 +182,9 @@ namespace FirstPlugin
}
else
{
CurveIndex++;
matAnimData.TexturePatternCurveIndex = CurveIndex++;
matAnimData.BeginVisalConstantIndex = 0;
matAnimData.Curves = ConvertAnimCurveWiiUToSwitch(texPatternAnim.TexPatternMatAnims[m].Curves);
}
@ -281,5 +387,128 @@ namespace FirstPlugin
return ska;
}
private static ResU.GX2.GX2CompSel ConvertBNTXToWiiUChannel(ResGFXBNTX.ChannelType compNX)
{
ResU.GX2.GX2CompSel type = new ResU.GX2.GX2CompSel();
switch (compNX)
{
case ResGFXBNTX.ChannelType.Zero:
type = ResU.GX2.GX2CompSel.Always0;
break;
case ResGFXBNTX.ChannelType.One:
type = ResU.GX2.GX2CompSel.Always1;
break;
case ResGFXBNTX.ChannelType.Alpha:
type = ResU.GX2.GX2CompSel.ChannelA;
break;
case ResGFXBNTX.ChannelType.Blue:
type = ResU.GX2.GX2CompSel.ChannelB;
break;
case ResGFXBNTX.ChannelType.Green:
type = ResU.GX2.GX2CompSel.ChannelG;
break;
case ResGFXBNTX.ChannelType.Red:
type = ResU.GX2.GX2CompSel.ChannelR;
break;
}
return type;
}
private static ResGFXBNTX.ChannelType ConvertWiiUToBNTXChannel(ResU.GX2.GX2CompSel compU)
{
ResGFXBNTX.ChannelType type = new ResGFXBNTX.ChannelType();
switch (compU)
{
case ResU.GX2.GX2CompSel.Always0:
type = ResGFXBNTX.ChannelType.Zero;
break;
case ResU.GX2.GX2CompSel.Always1:
type = ResGFXBNTX.ChannelType.One;
break;
case ResU.GX2.GX2CompSel.ChannelA:
type = ResGFXBNTX.ChannelType.Alpha;
break;
case ResU.GX2.GX2CompSel.ChannelB:
type = ResGFXBNTX.ChannelType.Blue;
break;
case ResU.GX2.GX2CompSel.ChannelG:
type = ResGFXBNTX.ChannelType.Green;
break;
case ResU.GX2.GX2CompSel.ChannelR:
type = ResGFXBNTX.ChannelType.Red;
break;
}
return type;
}
private static ResU.GX2.GX2SurfaceFormat ConvertSwitchToGX2Format(ResGFXBNTX.SurfaceFormat Format)
{
switch (Format)
{
case ResGFXBNTX.SurfaceFormat.BC1_SRGB: return ResU.GX2.GX2SurfaceFormat.T_BC1_SRGB;
case ResGFXBNTX.SurfaceFormat.BC1_UNORM: return ResU.GX2.GX2SurfaceFormat.T_BC1_UNorm;
case ResGFXBNTX.SurfaceFormat.BC2_SRGB: return ResU.GX2.GX2SurfaceFormat.T_BC2_SRGB;
case ResGFXBNTX.SurfaceFormat.BC2_UNORM: return ResU.GX2.GX2SurfaceFormat.T_BC2_UNorm;
case ResGFXBNTX.SurfaceFormat.BC3_SRGB: return ResU.GX2.GX2SurfaceFormat.T_BC3_SRGB;
case ResGFXBNTX.SurfaceFormat.BC3_UNORM: return ResU.GX2.GX2SurfaceFormat.T_BC3_UNorm;
case ResGFXBNTX.SurfaceFormat.BC4_SNORM: return ResU.GX2.GX2SurfaceFormat.T_BC4_SNorm;
case ResGFXBNTX.SurfaceFormat.BC4_UNORM: return ResU.GX2.GX2SurfaceFormat.T_BC4_UNorm;
case ResGFXBNTX.SurfaceFormat.BC5_SNORM: return ResU.GX2.GX2SurfaceFormat.T_BC5_SNorm;
case ResGFXBNTX.SurfaceFormat.BC5_UNORM: return ResU.GX2.GX2SurfaceFormat.T_BC5_UNorm;
case ResGFXBNTX.SurfaceFormat.R8_G8_B8_A8_SRGB: return ResU.GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_SRGB;
case ResGFXBNTX.SurfaceFormat.R8_G8_B8_A8_UNORM: return ResU.GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNorm;
case ResGFXBNTX.SurfaceFormat.A1_B5_G5_R5_UNORM: return ResU.GX2.GX2SurfaceFormat.TC_A1_B5_G5_R5_UNorm;
case ResGFXBNTX.SurfaceFormat.R5_G5_B5_A1_UNORM: return ResU.GX2.GX2SurfaceFormat.TC_R5_G5_B5_A1_UNorm;
case ResGFXBNTX.SurfaceFormat.R16_G16_B16_A16_UNORM: return ResU.GX2.GX2SurfaceFormat.TC_R16_G16_B16_A16_UNorm;
case ResGFXBNTX.SurfaceFormat.R16_G16_UNORM: return ResU.GX2.GX2SurfaceFormat.TC_R16_G16_UNorm;
case ResGFXBNTX.SurfaceFormat.R16_UNORM: return ResU.GX2.GX2SurfaceFormat.TCD_R16_UNorm;
case ResGFXBNTX.SurfaceFormat.R10_G10_B10_A2_UNORM: return ResU.GX2.GX2SurfaceFormat.TCS_R10_G10_B10_A2_UNorm;
case ResGFXBNTX.SurfaceFormat.R4_G4_B4_A4_UNORM: return ResU.GX2.GX2SurfaceFormat.TC_R4_G4_B4_A4_UNorm;
case ResGFXBNTX.SurfaceFormat.R4_G4_UNORM: return ResU.GX2.GX2SurfaceFormat.T_R4_G4_UNorm;
case ResGFXBNTX.SurfaceFormat.R5_G6_B5_UNORM: return ResU.GX2.GX2SurfaceFormat.TCS_R5_G6_B5_UNorm;
case ResGFXBNTX.SurfaceFormat.R8_G8_UNORM: return ResU.GX2.GX2SurfaceFormat.TC_R8_G8_UNorm;
case ResGFXBNTX.SurfaceFormat.R8_UNORM: return ResU.GX2.GX2SurfaceFormat.TC_R8_UNorm;
default:
throw new Exception("Unsuppored format " + Format);
}
}
private static ResGFXBNTX.SurfaceFormat ConvertGX2ToSwitchFormat(ResU.GX2.GX2SurfaceFormat Format)
{
switch (Format)
{
case ResU.GX2.GX2SurfaceFormat.T_BC1_SRGB: return ResGFXBNTX.SurfaceFormat.BC1_SRGB;
case ResU.GX2.GX2SurfaceFormat.T_BC1_UNorm: return ResGFXBNTX.SurfaceFormat.BC1_UNORM;
case ResU.GX2.GX2SurfaceFormat.T_BC2_SRGB: return ResGFXBNTX.SurfaceFormat.BC2_SRGB;
case ResU.GX2.GX2SurfaceFormat.T_BC2_UNorm: return ResGFXBNTX.SurfaceFormat.BC2_UNORM;
case ResU.GX2.GX2SurfaceFormat.T_BC3_SRGB: return ResGFXBNTX.SurfaceFormat.BC3_SRGB;
case ResU.GX2.GX2SurfaceFormat.T_BC3_UNorm: return ResGFXBNTX.SurfaceFormat.BC3_UNORM;
case ResU.GX2.GX2SurfaceFormat.T_BC4_SNorm: return ResGFXBNTX.SurfaceFormat.BC4_SNORM;
case ResU.GX2.GX2SurfaceFormat.T_BC4_UNorm: return ResGFXBNTX.SurfaceFormat.BC4_UNORM;
case ResU.GX2.GX2SurfaceFormat.T_BC5_SNorm: return ResGFXBNTX.SurfaceFormat.BC5_SNORM;
case ResU.GX2.GX2SurfaceFormat.T_BC5_UNorm: return ResGFXBNTX.SurfaceFormat.BC5_SNORM;
case ResU.GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_SRGB: return ResGFXBNTX.SurfaceFormat.R8_G8_B8_A8_SRGB;
case ResU.GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNorm: return ResGFXBNTX.SurfaceFormat.R8_G8_B8_A8_UNORM;
case ResU.GX2.GX2SurfaceFormat.TC_A1_B5_G5_R5_UNorm: return ResGFXBNTX.SurfaceFormat.A1_B5_G5_R5_UNORM;
case ResU.GX2.GX2SurfaceFormat.TC_R5_G5_B5_A1_UNorm: return ResGFXBNTX.SurfaceFormat.R5_G5_B5_A1_UNORM;
case ResU.GX2.GX2SurfaceFormat.TC_R16_G16_B16_A16_UNorm: return ResGFXBNTX.SurfaceFormat.R16_G16_B16_A16_UNORM;
case ResU.GX2.GX2SurfaceFormat.TC_R16_G16_UNorm: return ResGFXBNTX.SurfaceFormat.R16_G16_UNORM;
case ResU.GX2.GX2SurfaceFormat.TCD_R16_UNorm: return ResGFXBNTX.SurfaceFormat.R16_UNORM;
case ResU.GX2.GX2SurfaceFormat.TCS_R10_G10_B10_A2_UNorm: return ResGFXBNTX.SurfaceFormat.R10_G10_B10_A2_UNORM;
case ResU.GX2.GX2SurfaceFormat.TC_R4_G4_B4_A4_UNorm: return ResGFXBNTX.SurfaceFormat.R4_G4_B4_A4_UNORM;
case ResU.GX2.GX2SurfaceFormat.T_R4_G4_UNorm: return ResGFXBNTX.SurfaceFormat.R4_G4_UNORM;
case ResU.GX2.GX2SurfaceFormat.TCS_R5_G6_B5_UNorm: return ResGFXBNTX.SurfaceFormat.R5_G6_B5_UNORM;
case ResU.GX2.GX2SurfaceFormat.TC_R8_G8_UNorm: return ResGFXBNTX.SurfaceFormat.R8_G8_UNORM;
case ResU.GX2.GX2SurfaceFormat.TC_R8_UNorm: return ResGFXBNTX.SurfaceFormat.R8_UNORM;
default:
throw new Exception("Unsuppored format " + Format);
}
}
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Switch_Toolbox;
using System.Windows.Forms;
using Switch_Toolbox.Library;
namespace FirstPlugin
{
public class GFBMDL : TreeNodeFile, IFileFormat
{
public FileType FileType { get; set; } = FileType.Model;
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "Graphic Model" };
public string[] Extension { get; set; } = new string[] { "*.gfbmdl" };
public string FileName { get; set; }
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
public bool Identify(System.IO.Stream stream)
{
using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
{
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
bool IsMatch = reader.ReadUInt32() == 0x20000000;
reader.Position = 0;
return IsMatch;
}
}
public Type[] Types
{
get
{
List<Type> types = new List<Type>();
return types.ToArray();
}
}
public void Load(System.IO.Stream stream)
{
}
public void Unload()
{
}
public byte[] Save()
{
return null;
}
}
}

View File

@ -260,6 +260,7 @@ namespace FirstPlugin
// Formats.Add(typeof(BFLAN));
// Formats.Add(typeof(BFLYT));
Formats.Add(typeof(GFPAK));
Formats.Add(typeof(GFBMDL));
Formats.Add(typeof(NUTEXB));
Formats.Add(typeof(NUT));
Formats.Add(typeof(GTXFile));

View File

@ -219,7 +219,7 @@
<Compile Include="FileFormats\BCRES\Wrappers\CMDL\MTOBWrapper.cs" />
<Compile Include="FileFormats\BCRES\Wrappers\CMDL\SOBJWrapper.cs" />
<Compile Include="FileFormats\BCRES\Wrappers\TXOBWrapper.cs" />
<Compile Include="FileFormats\BFRES\Bfres Structs\BfresPlatformConverter.cs" />
<Compile Include="FileFormats\BFRES\PlatformConverter\BfresPlatformConverter.cs" />
<Compile Include="FileFormats\BFRES\BFRESGroupNode.cs" />
<Compile Include="FileFormats\BFRES\BFRESAnimFolder.cs" />
<Compile Include="FileFormats\BFRES\BfresUtilies.cs" />
@ -232,6 +232,7 @@
<Compile Include="FileFormats\Effects\PTCL_WiiU.cs" />
<Compile Include="FileFormats\Font\BFFNT.cs" />
<Compile Include="FileFormats\Audio\Archives\BFGRP.cs" />
<Compile Include="FileFormats\GFBMDL\GFBMDL.cs" />
<Compile Include="FileFormats\Hashes\SAHT.cs" />
<Compile Include="FileFormats\Shader\NSWShaderDecompile.cs" />
<Compile Include="FileFormats\Shader\NUSHDB.cs" />

View File

@ -1 +1 @@
047c65264269a34c41a754cfab4e34dee3b8889d
e402c1ea3b5c6e74ab734c29926ae6969018fbfc

View File

@ -19,7 +19,7 @@ namespace Switch_Toolbox.Library.Forms
{
InitializeComponent();
CanResize = true;
CanResize = false;
stButton1.BackColor = FillColor;
}