1
0
mirror of synced 2025-01-31 04:13:51 +01:00

Fixes for importing new bones or creating new ones from skeleton parent

This commit is contained in:
KillzXGaming 2019-05-26 20:44:39 -04:00
parent 0763f080c0
commit 2fc0467d9b
8 changed files with 135 additions and 75 deletions

Binary file not shown.

View File

@ -1215,75 +1215,75 @@ namespace Bfres.Structs
public void OptmizeAttributeFormats()
{
foreach (var attribute in vertexAttributes)
for (int i = 0; i < vertexAttributes.Count; i++)
{
if (attribute.GetAttributeType() == VertexAttribute.AttributeType.Weight ||
attribute.GetAttributeType() == VertexAttribute.AttributeType.Index)
if (vertexAttributes[i].GetAttributeType() == VertexAttribute.AttributeType.Weight ||
vertexAttributes[i].GetAttributeType() == VertexAttribute.AttributeType.Index)
{
OptmizeIndicesWeights(attribute);
OptmizeIndicesWeights(vertexAttributes[i]);
}
}
}
private void OptmizeIndicesWeights(VertexAttribute attribute)
{
/* if (VertexSkinCount == 1)
{
switch (attribute.Format)
{
case ResGFX.AttribFormat.Format_32_32_32_32_Single:
case ResGFX.AttribFormat.Format_32_32_32_Single:
case ResGFX.AttribFormat.Format_32_32_Single:
attribute.Format = ResGFX.AttribFormat.Format_32_Single;
break;
case ResGFX.AttribFormat.Format_32_32_32_32_SInt:
case ResGFX.AttribFormat.Format_32_32_32_SInt:
case ResGFX.AttribFormat.Format_32_32_SInt:
attribute.Format = ResGFX.AttribFormat.Format_32_SInt;
break;
case ResGFX.AttribFormat.Format_32_32_32_32_UInt:
case ResGFX.AttribFormat.Format_32_32_32_UInt:
case ResGFX.AttribFormat.Format_32_32_UInt:
attribute.Format = ResGFX.AttribFormat.Format_32_UInt;
break;
case ResGFX.AttribFormat.Format_16_16_16_16_Single:
case ResGFX.AttribFormat.Format_16_16_Single:
attribute.Format = ResGFX.AttribFormat.Format_16_Single;
break;
case ResGFX.AttribFormat.Format_16_16_16_16_SInt:
case ResGFX.AttribFormat.Format_16_16_SInt:
attribute.Format = ResGFX.AttribFormat.Format_16_SInt;
break;
case ResGFX.AttribFormat.Format_16_16_16_16_UInt:
case ResGFX.AttribFormat.Format_16_16_UInt:
attribute.Format = ResGFX.AttribFormat.Format_16_UInt;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_UInt:
case ResGFX.AttribFormat.Format_8_8_UInt:
attribute.Format = ResGFX.AttribFormat.Format_8_UInt;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_SInt:
case ResGFX.AttribFormat.Format_8_8_SInt:
attribute.Format = ResGFX.AttribFormat.Format_8_SInt;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_SNorm:
case ResGFX.AttribFormat.Format_8_8_SNorm:
attribute.Format = ResGFX.AttribFormat.Format_8_SNorm;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_UNorm:
case ResGFX.AttribFormat.Format_8_8_UNorm:
attribute.Format = ResGFX.AttribFormat.Format_8_UNorm;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_SIntToSingle:
case ResGFX.AttribFormat.Format_8_8_SIntToSingle:
attribute.Format = ResGFX.AttribFormat.Format_8_SIntToSingle;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_UIntToSingle:
case ResGFX.AttribFormat.Format_8_8_UIntToSingle:
attribute.Format = ResGFX.AttribFormat.Format_8_UIntToSingle;
break;
}
}
/* if (VertexSkinCount == 1)
{
switch (attribute.Format)
{
case ResGFX.AttribFormat.Format_32_32_32_32_Single:
case ResGFX.AttribFormat.Format_32_32_32_Single:
case ResGFX.AttribFormat.Format_32_32_Single:
attribute.Format = ResGFX.AttribFormat.Format_32_Single;
break;
case ResGFX.AttribFormat.Format_32_32_32_32_SInt:
case ResGFX.AttribFormat.Format_32_32_32_SInt:
case ResGFX.AttribFormat.Format_32_32_SInt:
attribute.Format = ResGFX.AttribFormat.Format_32_SInt;
break;
case ResGFX.AttribFormat.Format_32_32_32_32_UInt:
case ResGFX.AttribFormat.Format_32_32_32_UInt:
case ResGFX.AttribFormat.Format_32_32_UInt:
attribute.Format = ResGFX.AttribFormat.Format_32_UInt;
break;
case ResGFX.AttribFormat.Format_16_16_16_16_Single:
case ResGFX.AttribFormat.Format_16_16_Single:
attribute.Format = ResGFX.AttribFormat.Format_16_Single;
break;
case ResGFX.AttribFormat.Format_16_16_16_16_SInt:
case ResGFX.AttribFormat.Format_16_16_SInt:
attribute.Format = ResGFX.AttribFormat.Format_16_SInt;
break;
case ResGFX.AttribFormat.Format_16_16_16_16_UInt:
case ResGFX.AttribFormat.Format_16_16_UInt:
attribute.Format = ResGFX.AttribFormat.Format_16_UInt;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_UInt:
case ResGFX.AttribFormat.Format_8_8_UInt:
attribute.Format = ResGFX.AttribFormat.Format_8_UInt;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_SInt:
case ResGFX.AttribFormat.Format_8_8_SInt:
attribute.Format = ResGFX.AttribFormat.Format_8_SInt;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_SNorm:
case ResGFX.AttribFormat.Format_8_8_SNorm:
attribute.Format = ResGFX.AttribFormat.Format_8_SNorm;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_UNorm:
case ResGFX.AttribFormat.Format_8_8_UNorm:
attribute.Format = ResGFX.AttribFormat.Format_8_UNorm;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_SIntToSingle:
case ResGFX.AttribFormat.Format_8_8_SIntToSingle:
attribute.Format = ResGFX.AttribFormat.Format_8_SIntToSingle;
break;
case ResGFX.AttribFormat.Format_8_8_8_8_UIntToSingle:
case ResGFX.AttribFormat.Format_8_8_UIntToSingle:
attribute.Format = ResGFX.AttribFormat.Format_8_UIntToSingle;
break;
}
}
if (VertexSkinCount == 2)
{
switch (attribute.Format)

View File

@ -191,6 +191,7 @@ namespace Bfres.Structs
public override void LoadContextMenus()
{
ContextMenuStrip = new STContextMenuStrip();
ContextMenuStrip.Items.Add(new ToolStripMenuItem("New Bone", null, NewBoneAction, Keys.Control | Keys.N));
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Import Bone", null, ImportAction, Keys.Control | Keys.I));
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Export All Bones", null, ExportAllAction, Keys.Control | Keys.B));
ContextMenuStrip.Items.Add(new ToolStripSeparator());
@ -201,6 +202,7 @@ namespace Bfres.Structs
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Replace Skeleton", null, ReplaceAction, Keys.Control | Keys.R));
}
protected void NewBoneAction(object sender, EventArgs args) { NewChildBone(); }
protected void ExportAllAction(object sender, EventArgs args) { ExportAl(); }
protected void ReplaceMatchingFileAction(object sender, EventArgs args) { ReplaceMatchingFile(); }
protected void ReplaceMatchingFolderAction(object sender, EventArgs args) { ReplaceMatchingFolder(); }
@ -365,6 +367,53 @@ namespace Bfres.Structs
return ((FMDL)Parent).GetResFileU();
}
public void NewChildBone()
{
BfresBone bone = new BfresBone(fskl);
bone.parentIndex = -1;
if (SkeletonU != null)
{
bone.BoneU = new ResU.Bone();
bone.BoneU.Name = CheckDuplicateBoneNames("NewBone");
BfresWiiU.ReadBone(bone, bone.BoneU, false);
Nodes.Add(bone);
fskl.bones.Add(bone);
bone.Bone.ParentIndex = (short)bone.parentIndex;
fskl.AddBone(bone.BoneU);
}
else
{
bone.Bone = new Bone();
bone.Bone.Name = CheckDuplicateBoneNames("NewBone");
BfresSwitch.ReadBone(bone, bone.Bone, false);
Nodes.Add(bone);
fskl.bones.Add(bone);
bone.Bone.ParentIndex = (short)bone.parentIndex;
fskl.AddBone(bone.Bone);
}
}
int dupedIndex = 0;
private string CheckDuplicateBoneNames(string BoneName)
{
foreach (var bone in fskl.bones)
{
if (bone.Text == BoneName)
{
BoneName = $"{BoneName}{dupedIndex++}";
return CheckDuplicateBoneNames(BoneName);
}
}
return BoneName;
}
public override void Import(string[] FileNames)
{
foreach (var FileName in FileNames)
@ -382,6 +431,12 @@ namespace Bfres.Structs
bone.ParentIndex = -1;
BfresWiiU.ReadBone(bn, bone, false);
Nodes.Add(bn);
fskl.bones.Add(bn);
bone.ParentIndex = (short)bn.parentIndex;
fskl.AddBone(bn.Bone);
}
else
{
@ -390,6 +445,12 @@ namespace Bfres.Structs
bone.ParentIndex = -1;
BfresSwitch.ReadBone(bn, bone, false);
Nodes.Add(bn);
fskl.bones.Add(bn);
bn.Bone.ParentIndex = (short)bn.parentIndex;
fskl.AddBone(bn.Bone);
}
}
}

View File

@ -163,9 +163,6 @@ namespace Bfres.Structs
private STSkeleton GetActiveSkeleton()
{
if (Parent == null)
return null;
var viewport = LibraryGUI.Instance.GetActiveViewport();
if (viewport != null)
{
@ -183,17 +180,19 @@ namespace Bfres.Structs
}
}
}
else
{
foreach (var model in ((BFRES)Parent.Parent.Parent).BFRESRender.models)
{
foreach (var bone in Bones)
{
var animBone = model.Skeleton.GetBone(bone.Text);
if (animBone != null)
return model.Skeleton;
}
var render = ((BFRES)Parent.Parent.Parent).BFRESRender;
if (render.models.Count == 1)
return render.models[0].Skeleton;
foreach (var model in render.models)
{
foreach (var bone in Bones)
{
var animBone = model.Skeleton.GetBone(bone.Text);
if (animBone != null)
return model.Skeleton;
}
}
@ -267,7 +266,7 @@ namespace Bfres.Structs
UpdateAnimation(ska);
}
else
throw new Exception("No skeleton found to assign!");
STErrorDialog.Show("No matching skeleton bones found to assign!", "Skeleton Importer", "");
}
else if (ext == ".chr0")
{