mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 12:33:12 +00:00
Fix bfres importing bugs and alignment corruption from importing sections
This commit is contained in:
parent
007376e891
commit
79036ecb95
26 changed files with 107 additions and 64 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -54,6 +54,7 @@ namespace FirstPlugin
|
|||
public STToolStripItem[] TitleBarExtensions => null;
|
||||
public STToolStripItem[] CompressionMenuExtensions => null;
|
||||
public STToolStripItem[] ExperimentalMenuExtensions => experimentalMenu;
|
||||
public STToolStripItem[] EditMenuExtensions => null;
|
||||
|
||||
STToolStripItem[] experimentalMenu = new STToolStripItem[1];
|
||||
public MenuExt()
|
||||
|
|
|
@ -55,6 +55,7 @@ namespace FirstPlugin
|
|||
{
|
||||
public STToolStripItem[] NewFileMenuExtensions => newFileExt;
|
||||
public STToolStripItem[] NewFromFileMenuExtensions => null;
|
||||
public STToolStripItem[] EditMenuExtensions => editExt;
|
||||
public STToolStripItem[] ToolsMenuExtensions => toolExt;
|
||||
public STToolStripItem[] TitleBarExtensions => null;
|
||||
public STToolStripItem[] CompressionMenuExtensions => null;
|
||||
|
@ -62,9 +63,13 @@ namespace FirstPlugin
|
|||
|
||||
STToolStripItem[] toolExt = new STToolStripItem[1];
|
||||
STToolStripItem[] newFileExt = new STToolStripItem[2];
|
||||
STToolStripItem[] editExt = new STToolStripItem[1];
|
||||
|
||||
public MenuExt()
|
||||
{
|
||||
editExt[0] = new STToolStripItem("Use Advanced Editor As Default");
|
||||
editExt[0].Click += AdvancedEditor;
|
||||
|
||||
toolExt[0] = new STToolStripItem("Open Bfres Debugger");
|
||||
toolExt[0].Click += DebugInfo;
|
||||
|
||||
|
@ -72,6 +77,21 @@ namespace FirstPlugin
|
|||
newFileExt[0].Click += NewSwitchBfres;
|
||||
newFileExt[1] = new STToolStripItem("BFRES (Wii U)");
|
||||
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)
|
||||
{
|
||||
|
@ -178,7 +198,43 @@ namespace FirstPlugin
|
|||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -620,7 +620,6 @@ namespace Bfres.Structs
|
|||
shape.CreateNewBoundingBoxes();
|
||||
shape.CreateBoneList(obj, this);
|
||||
shape.CreateIndexList(obj, this);
|
||||
//Todo find better way. Currently uses import settings now
|
||||
shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex));
|
||||
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
|
||||
shape.BoneIndices = shape.GetIndices(Skeleton);
|
||||
|
@ -863,6 +862,7 @@ namespace Bfres.Structs
|
|||
|
||||
shape.VertexBufferIndex = shapes.Count;
|
||||
shape.vertices = obj.vertices;
|
||||
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
|
||||
shape.vertexAttributes = settings.CreateNewAttributes();
|
||||
shape.BoneIndex = obj.BoneIndex;
|
||||
|
||||
|
@ -880,7 +880,6 @@ namespace Bfres.Structs
|
|||
shape.CreateBoneList(obj, this);
|
||||
shape.CreateIndexList(obj, this);
|
||||
shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex));
|
||||
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
|
||||
shape.BoneIndices = shape.GetIndices(Skeleton);
|
||||
|
||||
shape.SaveShape(IsWiiU);
|
||||
|
|
|
@ -369,8 +369,6 @@ namespace Bfres.Structs
|
|||
|
||||
public void ApplyImportSettings(BfresModelImportSettings settings, FMAT mat)
|
||||
{
|
||||
// VertexSkinCount = settings.SkinCountLimit;
|
||||
|
||||
if (settings.FlipUVsVertical)
|
||||
{
|
||||
foreach (Vertex v in vertices)
|
||||
|
@ -670,8 +668,10 @@ namespace Bfres.Structs
|
|||
ApplyImportSettings(settings, GetMaterial());
|
||||
lodMeshes = obj.lodMeshes;
|
||||
CreateNewBoundingBoxes();
|
||||
|
||||
SaveShape(IsWiiU);
|
||||
SaveVertexBuffer();
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
@ -1108,8 +1108,8 @@ namespace Bfres.Structs
|
|||
if (VertexSkinCount == 1 && vtx.boneIds.Count > 0)
|
||||
boneId = vtx.boneIds[0];
|
||||
|
||||
vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
|
||||
vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
|
||||
// vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
|
||||
// vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
|
||||
}
|
||||
// Console.WriteLine($"Weight count {vtx.boneWeights.Count}");
|
||||
// Console.WriteLine($"Index count {vtx.boneIds.Count}");
|
||||
|
|
|
@ -2587,15 +2587,6 @@ namespace Bfres.Structs
|
|||
}
|
||||
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()
|
||||
{
|
||||
if (BFRES.IsWiiU)
|
||||
|
|
|
@ -142,6 +142,7 @@ namespace FirstPlugin
|
|||
box.Extend = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);
|
||||
fshp.boundingBoxes.Add(box);
|
||||
}
|
||||
|
||||
foreach (float rad in shp.RadiusArray)
|
||||
{
|
||||
fshp.boundingRadius.Add(rad);
|
||||
|
@ -289,7 +290,7 @@ namespace FirstPlugin
|
|||
if (vec4c0.Length > 0)
|
||||
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;
|
||||
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].GetScale());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
fshp.vertices.Add(v);
|
||||
}
|
||||
}
|
||||
|
@ -851,12 +852,16 @@ namespace FirstPlugin
|
|||
ShapeU.KeyShapes = new ResDict<KeyShape>();
|
||||
ShapeU.Name = fshp.Text;
|
||||
ShapeU.TargetAttribCount = (byte)fshp.TargetAttribCount;
|
||||
ShapeU.SkinBoneIndices = fshp.BoneIndices;
|
||||
ShapeU.SubMeshBoundings = new List<Bounding>();
|
||||
ShapeU.RadiusArray = new List<float>();
|
||||
ShapeU.RadiusArray = fshp.boundingRadius;
|
||||
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)
|
||||
{
|
||||
Bounding bnd = new Bounding();
|
||||
|
|
|
@ -83,6 +83,7 @@ namespace FirstPlugin
|
|||
public STToolStripItem[] TitleBarExtensions => null;
|
||||
public STToolStripItem[] CompressionMenuExtensions => null;
|
||||
public STToolStripItem[] ExperimentalMenuExtensions => null;
|
||||
public STToolStripItem[] EditMenuExtensions => null;
|
||||
|
||||
STToolStripItem[] newFileExt = new STToolStripItem[2];
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ namespace FirstPlugin
|
|||
public STToolStripItem[] TitleBarExtensions => null;
|
||||
public STToolStripItem[] CompressionMenuExtensions => null;
|
||||
public STToolStripItem[] ExperimentalMenuExtensions => null;
|
||||
public STToolStripItem[] EditMenuExtensions => null;
|
||||
|
||||
STToolStripItem[] toolExt = new STToolStripItem[1];
|
||||
STToolStripItem[] newFileExt = new STToolStripItem[1];
|
||||
|
|
|
@ -239,6 +239,7 @@ namespace FirstPlugin
|
|||
public STToolStripItem[] TitleBarExtensions => null;
|
||||
public STToolStripItem[] CompressionMenuExtensions => null;
|
||||
public STToolStripItem[] ExperimentalMenuExtensions => null;
|
||||
public STToolStripItem[] EditMenuExtensions => null;
|
||||
|
||||
STToolStripItem[] newFileExt = new STToolStripItem[1];
|
||||
public MenuExt()
|
||||
|
|
|
@ -61,8 +61,6 @@
|
|||
this.chkBoxFlipUvsY = new Switch_Toolbox.Library.Forms.STCheckBox();
|
||||
this.chkBoxImportBones = new Switch_Toolbox.Library.Forms.STCheckBox();
|
||||
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.chkBoxParamDefaults = new Switch_Toolbox.Library.Forms.STCheckBox();
|
||||
this.chkBoxRotNegative90Y = new Switch_Toolbox.Library.Forms.STCheckBox();
|
||||
|
@ -97,7 +95,6 @@
|
|||
this.panel6.SuspendLayout();
|
||||
this.panel7.SuspendLayout();
|
||||
this.panel8.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInt1)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.panel9.SuspendLayout();
|
||||
this.tabControl1.SuspendLayout();
|
||||
|
@ -442,8 +439,6 @@
|
|||
//
|
||||
// panel8
|
||||
//
|
||||
this.panel8.Controls.Add(this.label16);
|
||||
this.panel8.Controls.Add(this.numericUpDownInt1);
|
||||
this.panel8.Controls.Add(this.chkBoxImportMat);
|
||||
this.panel8.Controls.Add(this.chkBoxParamDefaults);
|
||||
this.panel8.Controls.Add(this.chkBoxRotNegative90Y);
|
||||
|
@ -469,33 +464,6 @@
|
|||
this.panel8.Size = new System.Drawing.Size(524, 327);
|
||||
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
|
||||
//
|
||||
this.chkBoxImportMat.AutoSize = true;
|
||||
|
@ -805,7 +773,6 @@
|
|||
this.panel7.PerformLayout();
|
||||
this.panel8.ResumeLayout(false);
|
||||
this.panel8.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInt1)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.panel9.ResumeLayout(false);
|
||||
this.panel9.PerformLayout();
|
||||
|
@ -876,8 +843,6 @@
|
|||
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxRotNegative90Y;
|
||||
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxParamDefaults;
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -329,10 +329,5 @@ namespace FirstPlugin
|
|||
else
|
||||
EnableMaterialEdits();
|
||||
}
|
||||
|
||||
private void numericUpDownInt1_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
SkinCountLimit = (int)numericUpDownInt1.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -418,7 +418,6 @@ namespace Switch_Toolbox.Library
|
|||
}
|
||||
public List<Vertex> GetVertices(Mesh msh, Matrix4 transform, STGenericObject STobj)
|
||||
{
|
||||
|
||||
List<Vertex> vertices = new List<Vertex>();
|
||||
for (int v = 0; v < msh.VertexCount; v++)
|
||||
{
|
||||
|
|
|
@ -22,5 +22,6 @@ namespace Switch_Toolbox.Library
|
|||
STToolStripItem[] ToolsMenuExtensions { get; }
|
||||
STToolStripItem[] TitleBarExtensions { get; }
|
||||
STToolStripItem[] ExperimentalMenuExtensions { get; }
|
||||
STToolStripItem[] EditMenuExtensions { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,23 @@ namespace Switch_Toolbox.Library
|
|||
|
||||
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()
|
||||
{
|
||||
var editors = new List<IEditor<Forms.STForm>>();
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -40,6 +40,7 @@ namespace Toolbox
|
|||
tabForms.myBackColor = FormThemes.BaseTheme.FormBackColor;
|
||||
|
||||
OnMdiWindowClosed();
|
||||
ResetMenus();
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
|
@ -648,10 +649,20 @@ namespace Toolbox
|
|||
saveToolStripButton.Enabled = false;
|
||||
}
|
||||
|
||||
if (format.IFileInfo.UseEditMenu)
|
||||
editToolStripMenuItem.Enabled = true;
|
||||
else
|
||||
editToolStripMenuItem.Enabled = false;
|
||||
var menuExtensions = FileManager.GetMenuExtensions(format);
|
||||
|
||||
editToolStripMenuItem.DropDownItems.Clear();
|
||||
|
||||
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()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue