Start adding conversion methods for automatic wii u - switch conversion and vice versa

This commit is contained in:
KillzXGaming 2019-06-01 18:15:48 -04:00
parent 7cb5885e6f
commit e51fb070c6
10 changed files with 148 additions and 135 deletions

Binary file not shown.

View file

@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ResU = Syroot.NintenTools.Bfres;
using ResNX = Syroot.NintenTools.NSW.Bfres;
namespace FirstPlugin
{
public class BfresPlatformConverter
{
public static ResNX.SkeletalAnim ConvertWiiUToSwitch(ResU.SkeletalAnim skeletalAnimU)
{
ResNX.SkeletalAnim ska = new ResNX.SkeletalAnim();
ska.Name = skeletalAnimU.Name;
ska.Path = skeletalAnimU.Path;
ska.FrameCount = skeletalAnimU.FrameCount;
ska.FlagsScale = ResNX.SkeletalAnimFlagsScale.None;
if (skeletalAnimU.FlagsScale.HasFlag(ResU.SkeletalAnimFlagsScale.Maya))
ska.FlagsScale = ResNX.SkeletalAnimFlagsScale.Maya;
if (skeletalAnimU.FlagsScale.HasFlag(ResU.SkeletalAnimFlagsScale.Softimage))
ska.FlagsScale = ResNX.SkeletalAnimFlagsScale.Softimage;
if (skeletalAnimU.FlagsScale.HasFlag(ResU.SkeletalAnimFlagsScale.Standard))
ska.FlagsScale = ResNX.SkeletalAnimFlagsScale.Standard;
ska.FrameCount = skeletalAnimU.FrameCount;
ska.BindIndices = skeletalAnimU.BindIndices;
ska.BakedSize = skeletalAnimU.BakedSize;
ska.Loop = skeletalAnimU.Loop;
ska.Baked = skeletalAnimU.Baked;
foreach (var boneAnimU in skeletalAnimU.BoneAnims)
{
var boneAnim = new ResNX.BoneAnim();
ska.BoneAnims.Add(boneAnim);
boneAnim.Name = boneAnimU.Name;
boneAnim.BeginRotate = boneAnimU.BeginRotate;
boneAnim.BeginTranslate = boneAnimU.BeginTranslate;
boneAnim.BeginBaseTranslate = boneAnimU.BeginBaseTranslate;
var baseData = new ResNX.BoneAnimData();
baseData.Translate = boneAnimU.BaseData.Translate;
baseData.Scale = boneAnimU.BaseData.Scale;
baseData.Rotate = boneAnimU.BaseData.Rotate;
baseData.Flags = boneAnimU.BaseData.Flags;
boneAnim.BaseData = baseData;
boneAnim.FlagsBase = (ResNX.BoneAnimFlagsBase)boneAnimU.FlagsBase;
boneAnim.FlagsCurve = (ResNX.BoneAnimFlagsCurve)boneAnimU.FlagsCurve;
boneAnim.FlagsTransform = (ResNX.BoneAnimFlagsTransform)boneAnimU.FlagsTransform;
foreach (var curveU in boneAnimU.Curves)
{
ResNX.AnimCurve curve = new ResNX.AnimCurve();
curve.AnimDataOffset = curveU.AnimDataOffset;
curve.CurveType = (ResNX.AnimCurveType)curveU.CurveType;
curve.Delta = curveU.Delta;
curve.EndFrame = curveU.EndFrame;
curve.Frames = curveU.Frames;
curve.Keys = curveU.Keys;
curve.KeyStepBoolData = curveU.KeyStepBoolData;
curve.KeyType = (ResNX.AnimCurveKeyType)curveU.KeyType;
curve.FrameType = (ResNX.AnimCurveFrameType)curveU.FrameType;
curve.StartFrame = curveU.StartFrame;
curve.Scale = curveU.Scale;
curve.Offset = (float)curveU.Offset;
boneAnim.Curves.Add(curve);
}
}
return ska;
}
public static ResU.SkeletalAnim ConvertSwitchToWiiU(ResNX.SkeletalAnim skeletalAnimNX)
{
ResU.SkeletalAnim ska = new ResU.SkeletalAnim();
ska.Name = skeletalAnimNX.Name;
ska.Path = skeletalAnimNX.Path;
ska.FrameCount = skeletalAnimNX.FrameCount;
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.None;
if (skeletalAnimNX.FlagsScale.HasFlag(ResNX.SkeletalAnimFlagsScale.Maya))
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.Maya;
if (skeletalAnimNX.FlagsScale.HasFlag(ResNX.SkeletalAnimFlagsScale.Softimage))
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.Softimage;
if (skeletalAnimNX.FlagsScale.HasFlag(ResNX.SkeletalAnimFlagsScale.Standard))
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.Standard;
ska.FrameCount = skeletalAnimNX.FrameCount;
ska.BindIndices = skeletalAnimNX.BindIndices;
ska.BakedSize = skeletalAnimNX.BakedSize;
ska.Loop = skeletalAnimNX.Loop;
ska.Baked = skeletalAnimNX.Baked;
foreach (var boneAnimNX in skeletalAnimNX.BoneAnims)
{
var boneAnimU = new ResU.BoneAnim();
ska.BoneAnims.Add(boneAnimU);
boneAnimU.Name = boneAnimNX.Name;
boneAnimU.BeginRotate = boneAnimNX.BeginRotate;
boneAnimU.BeginTranslate = boneAnimNX.BeginTranslate;
boneAnimU.BeginBaseTranslate = boneAnimNX.BeginBaseTranslate;
var baseData = new ResU.BoneAnimData();
baseData.Translate = boneAnimNX.BaseData.Translate;
baseData.Scale = boneAnimNX.BaseData.Scale;
baseData.Rotate = boneAnimNX.BaseData.Rotate;
baseData.Flags = boneAnimNX.BaseData.Flags;
boneAnimU.BaseData = baseData;
boneAnimU.FlagsBase = (ResU.BoneAnimFlagsBase)boneAnimNX.FlagsBase;
boneAnimU.FlagsCurve = (ResU.BoneAnimFlagsCurve)boneAnimNX.FlagsCurve;
boneAnimU.FlagsTransform = (ResU.BoneAnimFlagsTransform)boneAnimNX.FlagsTransform;
foreach (var curveNX in boneAnimNX.Curves)
{
ResU.AnimCurve curve = new ResU.AnimCurve();
curve.AnimDataOffset = curveNX.AnimDataOffset;
curve.CurveType = (ResU.AnimCurveType)curveNX.CurveType;
curve.Delta = curveNX.Delta;
curve.EndFrame = curveNX.EndFrame;
curve.Frames = curveNX.Frames;
curve.Keys = curveNX.Keys;
curve.KeyStepBoolData = curveNX.KeyStepBoolData;
curve.KeyType = (ResU.AnimCurveKeyType)curveNX.KeyType;
curve.FrameType = (ResU.AnimCurveFrameType)curveNX.FrameType;
curve.StartFrame = curveNX.StartFrame;
curve.Scale = curveNX.Scale;
curve.Offset = (float)curveNX.Offset;
boneAnimU.Curves.Add(curve);
}
}
return ska;
}
}
}

View file

@ -126,7 +126,7 @@ namespace Bfres.Structs
STSkeleton skeleton = GetActiveSkeleton();
if (SkeletalAnimU != null)
BrawlboxHelper.FSKAConverter.Fska2Chr0(ConvertWiiUToSwitch(SkeletalAnimU), FileName);
BrawlboxHelper.FSKAConverter.Fska2Chr0(BfresPlatformConverter.ConvertWiiUToSwitch(SkeletalAnimU), FileName);
else
BrawlboxHelper.FSKAConverter.Fska2Chr0(SkeletalAnim, FileName);
@ -217,7 +217,7 @@ namespace Bfres.Structs
{
var ska = new SkeletalAnim();
ska.Import(FileName);
SkeletalAnimU = ConvertSwitchToWiiU(ska);
SkeletalAnimU = BfresPlatformConverter.ConvertSwitchToWiiU(ska);
SkeletalAnimU.Name = Text;
LoadAnim(SkeletalAnimU);
}
@ -241,7 +241,7 @@ namespace Bfres.Structs
//Create a new wii u skeletal anim and try to convert it instead
var ska = new ResU.SkeletalAnim();
ska.Import(FileName, new ResU.ResFile());
SkeletalAnim = ConvertWiiUToSwitch(ska);
SkeletalAnim = BfresPlatformConverter.ConvertWiiUToSwitch(ska);
SkeletalAnim.Name = Text;
LoadAnim(SkeletalAnim);
}
@ -296,7 +296,7 @@ namespace Bfres.Structs
{
if (IsWiiU)
{
SkeletalAnimU = ConvertSwitchToWiiU(FromGeneric(anims[i]));
SkeletalAnimU = BfresPlatformConverter.ConvertSwitchToWiiU(FromGeneric(anims[i]));
LoadAnim(SkeletalAnimU);
}
else
@ -315,7 +315,7 @@ namespace Bfres.Structs
if (SkeletalAnimU != null)
{
SkeletalAnimU = ConvertSwitchToWiiU(ska);
SkeletalAnimU = BfresPlatformConverter.ConvertSwitchToWiiU(ska);
LoadAnim(SkeletalAnimU);
}
else
@ -615,129 +615,6 @@ namespace Bfres.Structs
return 0;
}
public static SkeletalAnim ConvertWiiUToSwitch(ResU.SkeletalAnim skeletalAnimU)
{
SkeletalAnim ska = new SkeletalAnim();
ska.Name = skeletalAnimU.Name;
ska.Path = skeletalAnimU.Path;
ska.FrameCount = skeletalAnimU.FrameCount;
ska.FlagsScale = SkeletalAnimFlagsScale.None;
if (skeletalAnimU.FlagsScale.HasFlag(ResU.SkeletalAnimFlagsScale.Maya))
ska.FlagsScale = SkeletalAnimFlagsScale.Maya;
if (skeletalAnimU.FlagsScale.HasFlag(ResU.SkeletalAnimFlagsScale.Softimage))
ska.FlagsScale = SkeletalAnimFlagsScale.Softimage;
if (skeletalAnimU.FlagsScale.HasFlag(ResU.SkeletalAnimFlagsScale.Standard))
ska.FlagsScale = SkeletalAnimFlagsScale.Standard;
ska.FrameCount = skeletalAnimU.FrameCount;
ska.BindIndices = skeletalAnimU.BindIndices;
ska.BakedSize = skeletalAnimU.BakedSize;
ska.Loop = skeletalAnimU.Loop;
ska.Baked = skeletalAnimU.Baked;
foreach (var boneAnimU in skeletalAnimU.BoneAnims)
{
var boneAnim = new BoneAnim();
ska.BoneAnims.Add(boneAnim);
boneAnim.Name = boneAnimU.Name;
boneAnim.BeginRotate = boneAnimU.BeginRotate;
boneAnim.BeginTranslate = boneAnimU.BeginTranslate;
boneAnim.BeginBaseTranslate = boneAnimU.BeginBaseTranslate;
var baseData = new BoneAnimData();
baseData.Translate = boneAnimU.BaseData.Translate;
baseData.Scale = boneAnimU.BaseData.Scale;
baseData.Rotate = boneAnimU.BaseData.Rotate;
baseData.Flags = boneAnimU.BaseData.Flags;
boneAnim.BaseData = baseData;
boneAnim.FlagsBase = (BoneAnimFlagsBase)boneAnimU.FlagsBase;
boneAnim.FlagsCurve = (BoneAnimFlagsCurve)boneAnimU.FlagsCurve;
boneAnim.FlagsTransform = (BoneAnimFlagsTransform)boneAnimU.FlagsTransform;
foreach (var curveU in boneAnimU.Curves)
{
AnimCurve curve = new AnimCurve();
curve.AnimDataOffset = curveU.AnimDataOffset;
curve.CurveType = (AnimCurveType)curveU.CurveType;
curve.Delta = curveU.Delta;
curve.EndFrame = curveU.EndFrame;
curve.Frames = curveU.Frames;
curve.Keys = curveU.Keys;
curve.KeyStepBoolData = curveU.KeyStepBoolData;
curve.KeyType = (AnimCurveKeyType)curveU.KeyType;
curve.FrameType = (AnimCurveFrameType)curveU.FrameType;
curve.StartFrame = curveU.StartFrame;
curve.Scale = curveU.Scale;
curve.Offset = (float)curveU.Offset;
boneAnim.Curves.Add(curve);
}
}
return ska;
}
public static ResU.SkeletalAnim ConvertSwitchToWiiU(SkeletalAnim skeletalAnimNX)
{
ResU.SkeletalAnim ska = new ResU.SkeletalAnim();
ska.Name = skeletalAnimNX.Name;
ska.Path = skeletalAnimNX.Path;
ska.FrameCount = skeletalAnimNX.FrameCount;
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.None;
if (skeletalAnimNX.FlagsScale.HasFlag(SkeletalAnimFlagsScale.Maya))
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.Maya;
if (skeletalAnimNX.FlagsScale.HasFlag(SkeletalAnimFlagsScale.Softimage))
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.Softimage;
if (skeletalAnimNX.FlagsScale.HasFlag(SkeletalAnimFlagsScale.Standard))
ska.FlagsScale = ResU.SkeletalAnimFlagsScale.Standard;
ska.FrameCount = skeletalAnimNX.FrameCount;
ska.BindIndices = skeletalAnimNX.BindIndices;
ska.BakedSize = skeletalAnimNX.BakedSize;
ska.Loop = skeletalAnimNX.Loop;
ska.Baked = skeletalAnimNX.Baked;
foreach (var boneAnimNX in skeletalAnimNX.BoneAnims)
{
var boneAnimU = new ResU.BoneAnim();
ska.BoneAnims.Add(boneAnimU);
boneAnimU.Name = boneAnimNX.Name;
boneAnimU.BeginRotate = boneAnimNX.BeginRotate;
boneAnimU.BeginTranslate = boneAnimNX.BeginTranslate;
boneAnimU.BeginBaseTranslate = boneAnimNX.BeginBaseTranslate;
var baseData = new ResU.BoneAnimData();
baseData.Translate = boneAnimNX.BaseData.Translate;
baseData.Scale = boneAnimNX.BaseData.Scale;
baseData.Rotate = boneAnimNX.BaseData.Rotate;
baseData.Flags = boneAnimNX.BaseData.Flags;
boneAnimU.BaseData = baseData;
boneAnimU.FlagsBase = (ResU.BoneAnimFlagsBase)boneAnimNX.FlagsBase;
boneAnimU.FlagsCurve = (ResU.BoneAnimFlagsCurve)boneAnimNX.FlagsCurve;
boneAnimU.FlagsTransform = (ResU.BoneAnimFlagsTransform)boneAnimNX.FlagsTransform;
foreach (var curveNX in boneAnimNX.Curves)
{
ResU.AnimCurve curve = new ResU.AnimCurve();
curve.AnimDataOffset = curveNX.AnimDataOffset;
curve.CurveType = (ResU.AnimCurveType)curveNX.CurveType;
curve.Delta = curveNX.Delta;
curve.EndFrame = curveNX.EndFrame;
curve.Frames = curveNX.Frames;
curve.Keys = curveNX.Keys;
curve.KeyStepBoolData = curveNX.KeyStepBoolData;
curve.KeyType = (ResU.AnimCurveKeyType)curveNX.KeyType;
curve.FrameType = (ResU.AnimCurveFrameType)curveNX.FrameType;
curve.StartFrame = curveNX.StartFrame;
curve.Scale = curveNX.Scale;
curve.Offset = (float)curveNX.Offset;
boneAnimU.Curves.Add(curve);
}
}
return ska;
}
public FSKA(ResU.SkeletalAnim ska) { LoadAnim(ska); }
public FSKA(SkeletalAnim ska) { LoadAnim(ska); }
@ -901,7 +778,7 @@ namespace Bfres.Structs
if (SkeletalAnimU != null)
{
var SkeletalAnimNX = BrawlboxHelper.FSKAConverter.Anim2Fska(FileName);
SkeletalAnimU = ConvertSwitchToWiiU(SkeletalAnimNX);
SkeletalAnimU = BfresPlatformConverter.ConvertSwitchToWiiU(SkeletalAnimNX);
SkeletalAnimU.Name = Text;
LoadAnim(SkeletalAnimU);
}
@ -918,7 +795,7 @@ namespace Bfres.Structs
if (IsWiiU)
{
var SkeletalAnimNX = BrawlboxHelper.FSKAConverter.Chr02Fska(FileName);
SkeletalAnimU = ConvertSwitchToWiiU(SkeletalAnimNX);
SkeletalAnimU = BfresPlatformConverter.ConvertSwitchToWiiU(SkeletalAnimNX);
SkeletalAnimU.Name = Text;
LoadAnim(SkeletalAnimU);
}

View file

@ -219,6 +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\BFRESGroupNode.cs" />
<Compile Include="FileFormats\BFRES\BFRESAnimFolder.cs" />
<Compile Include="FileFormats\BFRES\BfresUtilies.cs" />

View file

@ -1 +1 @@
0f3130142d6535028095bd6218f41b0b18c3297d
257ba835e60e5df185147b3c27d6feb25ebe1d95

View file

@ -128,12 +128,10 @@ namespace Switch_Toolbox.Library.Forms
if (listViewCustom1.SelectedItems.Count > 0 && e.Button == MouseButtons.Right)
{
var item = listViewCustom1.SelectedItems[0];
if (item.Tag is TreeNode)
if (item.Tag != null && item.Tag is TreeNode)
{
// stContextMenuStrip1.Items.AddRange(((TreeNode)item.Tag).ContextMenuStrip.Items);
Point pt = listViewCustom1.PointToScreen(e.Location);
stContextMenuStrip1.Show(pt);
((TreeNode)item.Tag).ContextMenuStrip.Show(pt);
}
}
}