1
0
mirror of synced 2025-02-07 15:11:20 +01:00

Fix bfres importing bugs and alignment corruption from importing sections

This commit is contained in:
KillzXGaming 2019-04-12 15:34:42 -04:00
parent 007376e891
commit 79036ecb95
26 changed files with 107 additions and 64 deletions

Binary file not shown.

View File

@ -54,6 +54,7 @@ namespace FirstPlugin
public STToolStripItem[] TitleBarExtensions => null; public STToolStripItem[] TitleBarExtensions => null;
public STToolStripItem[] CompressionMenuExtensions => null; public STToolStripItem[] CompressionMenuExtensions => null;
public STToolStripItem[] ExperimentalMenuExtensions => experimentalMenu; public STToolStripItem[] ExperimentalMenuExtensions => experimentalMenu;
public STToolStripItem[] EditMenuExtensions => null;
STToolStripItem[] experimentalMenu = new STToolStripItem[1]; STToolStripItem[] experimentalMenu = new STToolStripItem[1];
public MenuExt() public MenuExt()

View File

@ -55,6 +55,7 @@ namespace FirstPlugin
{ {
public STToolStripItem[] NewFileMenuExtensions => newFileExt; public STToolStripItem[] NewFileMenuExtensions => newFileExt;
public STToolStripItem[] NewFromFileMenuExtensions => null; public STToolStripItem[] NewFromFileMenuExtensions => null;
public STToolStripItem[] EditMenuExtensions => editExt;
public STToolStripItem[] ToolsMenuExtensions => toolExt; public STToolStripItem[] ToolsMenuExtensions => toolExt;
public STToolStripItem[] TitleBarExtensions => null; public STToolStripItem[] TitleBarExtensions => null;
public STToolStripItem[] CompressionMenuExtensions => null; public STToolStripItem[] CompressionMenuExtensions => null;
@ -62,9 +63,13 @@ namespace FirstPlugin
STToolStripItem[] toolExt = new STToolStripItem[1]; STToolStripItem[] toolExt = new STToolStripItem[1];
STToolStripItem[] newFileExt = new STToolStripItem[2]; STToolStripItem[] newFileExt = new STToolStripItem[2];
STToolStripItem[] editExt = new STToolStripItem[1];
public MenuExt() public MenuExt()
{ {
editExt[0] = new STToolStripItem("Use Advanced Editor As Default");
editExt[0].Click += AdvancedEditor;
toolExt[0] = new STToolStripItem("Open Bfres Debugger"); toolExt[0] = new STToolStripItem("Open Bfres Debugger");
toolExt[0].Click += DebugInfo; toolExt[0].Click += DebugInfo;
@ -72,6 +77,21 @@ namespace FirstPlugin
newFileExt[0].Click += NewSwitchBfres; newFileExt[0].Click += NewSwitchBfres;
newFileExt[1] = new STToolStripItem("BFRES (Wii U)"); newFileExt[1] = new STToolStripItem("BFRES (Wii U)");
newFileExt[1].Click += NewWiiUBfres; newFileExt[1].Click += NewWiiUBfres;
editExt[0].Checked = !PluginRuntime.UseSimpleBfresEditor;
}
private void AdvancedEditor(object sender, EventArgs args)
{
if (editExt[0].Checked)
{
editExt[0].Checked = false;
// PluginRuntime.UseSimpleBfresEditor = true;
}
else
{
editExt[0].Checked = true;
// PluginRuntime.UseSimpleBfresEditor = false;
}
} }
private void NewWiiUBfres(object sender, EventArgs args) private void NewWiiUBfres(object sender, EventArgs args)
{ {
@ -178,7 +198,43 @@ namespace FirstPlugin
if (IsSimpleEditor) if (IsSimpleEditor)
{ {
STPropertyGrid editor = (STPropertyGrid)LibraryGUI.Instance.GetActiveContent(typeof(STPropertyGrid));
if (editor == null)
{
editor = new STPropertyGrid();
editor.Dock = DockStyle.Fill;
LibraryGUI.Instance.LoadEditor(editor);
}
editor.Text = Text;
if (SelectedSection is BFRES)
{
if (resFile != null)
editor.LoadProperty(resFile, OnPropertyChanged);
else
editor.LoadProperty(resFileU, OnPropertyChanged);
}
if (SelectedSection is FMDL)
{
if (((FMDL)SelectedSection).ModelU != null)
editor.LoadProperty(((FMDL)SelectedSection).ModelU, OnPropertyChanged);
else
editor.LoadProperty(((FMDL)SelectedSection).Model, OnPropertyChanged);
}
if (SelectedSection is FSHP)
{
if (((FSHP)SelectedSection).ShapeU != null)
editor.LoadProperty(((FSHP)SelectedSection).ShapeU, OnPropertyChanged);
else
editor.LoadProperty(((FSHP)SelectedSection).Shape, OnPropertyChanged);
}
if (SelectedSection is FMAT)
{
if (((FMAT)SelectedSection).MaterialU != null)
editor.LoadProperty(((FMAT)SelectedSection).MaterialU, OnPropertyChanged);
else
editor.LoadProperty(((FMAT)SelectedSection).MaterialU, OnPropertyChanged);
}
} }
else else
{ {

View File

@ -620,7 +620,6 @@ namespace Bfres.Structs
shape.CreateNewBoundingBoxes(); shape.CreateNewBoundingBoxes();
shape.CreateBoneList(obj, this); shape.CreateBoneList(obj, this);
shape.CreateIndexList(obj, this); shape.CreateIndexList(obj, this);
//Todo find better way. Currently uses import settings now
shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex)); shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex));
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount(); shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
shape.BoneIndices = shape.GetIndices(Skeleton); shape.BoneIndices = shape.GetIndices(Skeleton);
@ -863,6 +862,7 @@ namespace Bfres.Structs
shape.VertexBufferIndex = shapes.Count; shape.VertexBufferIndex = shapes.Count;
shape.vertices = obj.vertices; shape.vertices = obj.vertices;
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
shape.vertexAttributes = settings.CreateNewAttributes(); shape.vertexAttributes = settings.CreateNewAttributes();
shape.BoneIndex = obj.BoneIndex; shape.BoneIndex = obj.BoneIndex;
@ -880,7 +880,6 @@ namespace Bfres.Structs
shape.CreateBoneList(obj, this); shape.CreateBoneList(obj, this);
shape.CreateIndexList(obj, this); shape.CreateIndexList(obj, this);
shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex)); shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex));
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
shape.BoneIndices = shape.GetIndices(Skeleton); shape.BoneIndices = shape.GetIndices(Skeleton);
shape.SaveShape(IsWiiU); shape.SaveShape(IsWiiU);

View File

@ -369,8 +369,6 @@ namespace Bfres.Structs
public void ApplyImportSettings(BfresModelImportSettings settings, FMAT mat) public void ApplyImportSettings(BfresModelImportSettings settings, FMAT mat)
{ {
// VertexSkinCount = settings.SkinCountLimit;
if (settings.FlipUVsVertical) if (settings.FlipUVsVertical)
{ {
foreach (Vertex v in vertices) foreach (Vertex v in vertices)
@ -670,8 +668,10 @@ namespace Bfres.Structs
ApplyImportSettings(settings, GetMaterial()); ApplyImportSettings(settings, GetMaterial());
lodMeshes = obj.lodMeshes; lodMeshes = obj.lodMeshes;
CreateNewBoundingBoxes(); CreateNewBoundingBoxes();
SaveShape(IsWiiU); SaveShape(IsWiiU);
SaveVertexBuffer(); SaveVertexBuffer();
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
} }
@ -1108,8 +1108,8 @@ namespace Bfres.Structs
if (VertexSkinCount == 1 && vtx.boneIds.Count > 0) if (VertexSkinCount == 1 && vtx.boneIds.Count > 0)
boneId = vtx.boneIds[0]; boneId = vtx.boneIds[0];
vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1); // vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false); // vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
} }
// Console.WriteLine($"Weight count {vtx.boneWeights.Count}"); // Console.WriteLine($"Weight count {vtx.boneWeights.Count}");
// Console.WriteLine($"Index count {vtx.boneIds.Count}"); // Console.WriteLine($"Index count {vtx.boneIds.Count}");

View File

@ -2587,15 +2587,6 @@ namespace Bfres.Structs
} }
return indices; return indices;
} }
public Vector3 TransformLocal(Vector3 position, bool IsPos = true)
{
Matrix4 trans = Matrix4.CreateTranslation(0, 0, 0);
if (IsPos)
return Vector3.TransformPosition(position, trans);
else
return Vector3.TransformNormal(position, trans);
}
public void SaveVertexBuffer() public void SaveVertexBuffer()
{ {
if (BFRES.IsWiiU) if (BFRES.IsWiiU)

View File

@ -142,6 +142,7 @@ namespace FirstPlugin
box.Extend = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z); box.Extend = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);
fshp.boundingBoxes.Add(box); fshp.boundingBoxes.Add(box);
} }
foreach (float rad in shp.RadiusArray) foreach (float rad in shp.RadiusArray)
{ {
fshp.boundingRadius.Add(rad); fshp.boundingRadius.Add(rad);
@ -289,7 +290,7 @@ namespace FirstPlugin
if (vec4c0.Length > 0) if (vec4c0.Length > 0)
v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W); v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W);
if (fshp.VertexSkinCount == 1) /* if (fshp.VertexSkinCount == 1)
{ {
Matrix4 sb = model.Skeleton.bones[model.Skeleton.Node_Array[v.boneIds[0]]].Transform; Matrix4 sb = model.Skeleton.bones[model.Skeleton.Node_Array[v.boneIds[0]]].Transform;
v.pos = Vector3.TransformPosition(v.pos, sb); v.pos = Vector3.TransformPosition(v.pos, sb);
@ -312,7 +313,7 @@ namespace FirstPlugin
Console.WriteLine(model.Skeleton.bones[fshp.BoneIndex].GetRotation()); Console.WriteLine(model.Skeleton.bones[fshp.BoneIndex].GetRotation());
Console.WriteLine(model.Skeleton.bones[fshp.BoneIndex].GetScale()); Console.WriteLine(model.Skeleton.bones[fshp.BoneIndex].GetScale());
} }
} }*/
fshp.vertices.Add(v); fshp.vertices.Add(v);
} }
} }
@ -851,12 +852,16 @@ namespace FirstPlugin
ShapeU.KeyShapes = new ResDict<KeyShape>(); ShapeU.KeyShapes = new ResDict<KeyShape>();
ShapeU.Name = fshp.Text; ShapeU.Name = fshp.Text;
ShapeU.TargetAttribCount = (byte)fshp.TargetAttribCount; ShapeU.TargetAttribCount = (byte)fshp.TargetAttribCount;
ShapeU.SkinBoneIndices = fshp.BoneIndices;
ShapeU.SubMeshBoundings = new List<Bounding>(); ShapeU.SubMeshBoundings = new List<Bounding>();
ShapeU.RadiusArray = new List<float>(); ShapeU.RadiusArray = new List<float>();
ShapeU.RadiusArray = fshp.boundingRadius;
ShapeU.Meshes = new List<Mesh>(); ShapeU.Meshes = new List<Mesh>();
foreach (ushort index in fshp.BoneIndices)
ShapeU.SkinBoneIndices.Add(index);
foreach (float radius in fshp.boundingRadius)
ShapeU.RadiusArray.Add(radius);
foreach (FSHP.BoundingBox box in fshp.boundingBoxes) foreach (FSHP.BoundingBox box in fshp.boundingBoxes)
{ {
Bounding bnd = new Bounding(); Bounding bnd = new Bounding();

View File

@ -83,6 +83,7 @@ namespace FirstPlugin
public STToolStripItem[] TitleBarExtensions => null; public STToolStripItem[] TitleBarExtensions => null;
public STToolStripItem[] CompressionMenuExtensions => null; public STToolStripItem[] CompressionMenuExtensions => null;
public STToolStripItem[] ExperimentalMenuExtensions => null; public STToolStripItem[] ExperimentalMenuExtensions => null;
public STToolStripItem[] EditMenuExtensions => null;
STToolStripItem[] newFileExt = new STToolStripItem[2]; STToolStripItem[] newFileExt = new STToolStripItem[2];

View File

@ -60,6 +60,7 @@ namespace FirstPlugin
public STToolStripItem[] TitleBarExtensions => null; public STToolStripItem[] TitleBarExtensions => null;
public STToolStripItem[] CompressionMenuExtensions => null; public STToolStripItem[] CompressionMenuExtensions => null;
public STToolStripItem[] ExperimentalMenuExtensions => null; public STToolStripItem[] ExperimentalMenuExtensions => null;
public STToolStripItem[] EditMenuExtensions => null;
STToolStripItem[] toolExt = new STToolStripItem[1]; STToolStripItem[] toolExt = new STToolStripItem[1];
STToolStripItem[] newFileExt = new STToolStripItem[1]; STToolStripItem[] newFileExt = new STToolStripItem[1];

View File

@ -239,6 +239,7 @@ namespace FirstPlugin
public STToolStripItem[] TitleBarExtensions => null; public STToolStripItem[] TitleBarExtensions => null;
public STToolStripItem[] CompressionMenuExtensions => null; public STToolStripItem[] CompressionMenuExtensions => null;
public STToolStripItem[] ExperimentalMenuExtensions => null; public STToolStripItem[] ExperimentalMenuExtensions => null;
public STToolStripItem[] EditMenuExtensions => null;
STToolStripItem[] newFileExt = new STToolStripItem[1]; STToolStripItem[] newFileExt = new STToolStripItem[1];
public MenuExt() public MenuExt()

View File

@ -61,8 +61,6 @@
this.chkBoxFlipUvsY = new Switch_Toolbox.Library.Forms.STCheckBox(); this.chkBoxFlipUvsY = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkBoxImportBones = new Switch_Toolbox.Library.Forms.STCheckBox(); this.chkBoxImportBones = new Switch_Toolbox.Library.Forms.STCheckBox();
this.panel8 = new Switch_Toolbox.Library.Forms.STPanel(); this.panel8 = new Switch_Toolbox.Library.Forms.STPanel();
this.label16 = new Switch_Toolbox.Library.Forms.STLabel();
this.numericUpDownInt1 = new Switch_Toolbox.Library.Forms.NumericUpDownInt();
this.chkBoxImportMat = new Switch_Toolbox.Library.Forms.STCheckBox(); this.chkBoxImportMat = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkBoxParamDefaults = new Switch_Toolbox.Library.Forms.STCheckBox(); this.chkBoxParamDefaults = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkBoxRotNegative90Y = new Switch_Toolbox.Library.Forms.STCheckBox(); this.chkBoxRotNegative90Y = new Switch_Toolbox.Library.Forms.STCheckBox();
@ -97,7 +95,6 @@
this.panel6.SuspendLayout(); this.panel6.SuspendLayout();
this.panel7.SuspendLayout(); this.panel7.SuspendLayout();
this.panel8.SuspendLayout(); this.panel8.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInt1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.panel9.SuspendLayout(); this.panel9.SuspendLayout();
this.tabControl1.SuspendLayout(); this.tabControl1.SuspendLayout();
@ -442,8 +439,6 @@
// //
// panel8 // panel8
// //
this.panel8.Controls.Add(this.label16);
this.panel8.Controls.Add(this.numericUpDownInt1);
this.panel8.Controls.Add(this.chkBoxImportMat); this.panel8.Controls.Add(this.chkBoxImportMat);
this.panel8.Controls.Add(this.chkBoxParamDefaults); this.panel8.Controls.Add(this.chkBoxParamDefaults);
this.panel8.Controls.Add(this.chkBoxRotNegative90Y); this.panel8.Controls.Add(this.chkBoxRotNegative90Y);
@ -469,33 +464,6 @@
this.panel8.Size = new System.Drawing.Size(524, 327); this.panel8.Size = new System.Drawing.Size(524, 327);
this.panel8.TabIndex = 11; this.panel8.TabIndex = 11;
// //
// label16
//
this.label16.AutoSize = true;
this.label16.Location = new System.Drawing.Point(242, 189);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(83, 13);
this.label16.TabIndex = 33;
this.label16.Text = "Skin Count Limit";
//
// numericUpDownInt1
//
this.numericUpDownInt1.Location = new System.Drawing.Point(243, 215);
this.numericUpDownInt1.Maximum = new decimal(new int[] {
2147483647,
0,
0,
0});
this.numericUpDownInt1.Minimum = new decimal(new int[] {
-2147483648,
0,
0,
-2147483648});
this.numericUpDownInt1.Name = "numericUpDownInt1";
this.numericUpDownInt1.Size = new System.Drawing.Size(140, 20);
this.numericUpDownInt1.TabIndex = 32;
this.numericUpDownInt1.ValueChanged += new System.EventHandler(this.numericUpDownInt1_ValueChanged);
//
// chkBoxImportMat // chkBoxImportMat
// //
this.chkBoxImportMat.AutoSize = true; this.chkBoxImportMat.AutoSize = true;
@ -805,7 +773,6 @@
this.panel7.PerformLayout(); this.panel7.PerformLayout();
this.panel8.ResumeLayout(false); this.panel8.ResumeLayout(false);
this.panel8.PerformLayout(); this.panel8.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInt1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel9.ResumeLayout(false); this.panel9.ResumeLayout(false);
this.panel9.PerformLayout(); this.panel9.PerformLayout();
@ -876,8 +843,6 @@
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxRotNegative90Y; private Switch_Toolbox.Library.Forms.STCheckBox chkBoxRotNegative90Y;
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxParamDefaults; private Switch_Toolbox.Library.Forms.STCheckBox chkBoxParamDefaults;
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxImportMat; private Switch_Toolbox.Library.Forms.STCheckBox chkBoxImportMat;
private Switch_Toolbox.Library.Forms.STLabel label16;
private Switch_Toolbox.Library.Forms.NumericUpDownInt numericUpDownInt1;
private Switch_Toolbox.Library.Forms.STPanel stPanel1; private Switch_Toolbox.Library.Forms.STPanel stPanel1;
} }
} }

View File

@ -329,10 +329,5 @@ namespace FirstPlugin
else else
EnableMaterialEdits(); EnableMaterialEdits();
} }
private void numericUpDownInt1_ValueChanged(object sender, EventArgs e)
{
SkinCountLimit = (int)numericUpDownInt1.Value;
}
} }
} }

View File

@ -418,7 +418,6 @@ namespace Switch_Toolbox.Library
} }
public List<Vertex> GetVertices(Mesh msh, Matrix4 transform, STGenericObject STobj) public List<Vertex> GetVertices(Mesh msh, Matrix4 transform, STGenericObject STobj)
{ {
List<Vertex> vertices = new List<Vertex>(); List<Vertex> vertices = new List<Vertex>();
for (int v = 0; v < msh.VertexCount; v++) for (int v = 0; v < msh.VertexCount; v++)
{ {

View File

@ -22,5 +22,6 @@ namespace Switch_Toolbox.Library
STToolStripItem[] ToolsMenuExtensions { get; } STToolStripItem[] ToolsMenuExtensions { get; }
STToolStripItem[] TitleBarExtensions { get; } STToolStripItem[] TitleBarExtensions { get; }
STToolStripItem[] ExperimentalMenuExtensions { get; } STToolStripItem[] ExperimentalMenuExtensions { get; }
STToolStripItem[] EditMenuExtensions { get; }
} }
} }

View File

@ -33,6 +33,23 @@ namespace Switch_Toolbox.Library
return types.ToArray(); return types.ToArray();
} }
public static IFileMenuExtension GetMenuExtensions(IFileFormat fileFormat)
{
foreach (Type type in fileFormat.Types)
{
Type[] interfaces_array = type.GetInterfaces();
for (int i = 0; i < interfaces_array.Length; i++)
{
if (interfaces_array[i] == typeof(IFileMenuExtension))
{
return (IFileMenuExtension)Activator.CreateInstance(type);
}
}
}
return null;
}
public static IEditor<Forms.STForm>[] GetEditors() public static IEditor<Forms.STForm>[] GetEditors()
{ {
var editors = new List<IEditor<Forms.STForm>>(); var editors = new List<IEditor<Forms.STForm>>();

View File

@ -40,6 +40,7 @@ namespace Toolbox
tabForms.myBackColor = FormThemes.BaseTheme.FormBackColor; tabForms.myBackColor = FormThemes.BaseTheme.FormBackColor;
OnMdiWindowClosed(); OnMdiWindowClosed();
ResetMenus();
} }
public void Reload() public void Reload()
@ -648,10 +649,20 @@ namespace Toolbox
saveToolStripButton.Enabled = false; saveToolStripButton.Enabled = false;
} }
if (format.IFileInfo.UseEditMenu) var menuExtensions = FileManager.GetMenuExtensions(format);
editToolStripMenuItem.Enabled = true;
else editToolStripMenuItem.DropDownItems.Clear();
editToolStripMenuItem.Enabled = false;
if (menuExtensions != null)
{
if (menuExtensions.EditMenuExtensions != null)
{
RegisterMenuExtIndex(editToolStripMenuItem, menuExtensions.EditMenuExtensions, editToolStripMenuItem.DropDownItems.Count);
if (editToolStripMenuItem.DropDownItems.Count > 0)
editToolStripMenuItem.Enabled = true;
}
}
} }
private void ResetMenus() private void ResetMenus()
{ {