1
0
mirror of synced 2025-01-31 12:23:52 +01:00

Cleanup and some optimizations

This commit is contained in:
KillzXGaming 2018-11-23 15:39:16 -05:00
parent 216d772dbb
commit b5ba944b69
15 changed files with 296 additions and 101 deletions

View File

@ -147,43 +147,44 @@ namespace FirstPlugin
{
var resFile = bfres.ResFileNode.resFile;
int CurMdl = 0;
foreach (FMDL model in bfres.models)
{
resFile.Models[CurMdl].Shapes.Clear();
resFile.Models[CurMdl].VertexBuffers.Clear();
resFile.Models[CurMdl].Materials.Clear();
int i = 0;
var duplicates = model.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);
foreach (var shape in duplicates)
shape.Text += i++;
foreach (FSHP shape in model.shapes)
{
CheckMissingTextures(shape);
BfresSwitch.SetShape(shape, shape.Shape);
resFile.Models[CurMdl].Shapes.Add(shape.Shape);
resFile.Models[CurMdl].VertexBuffers.Add(shape.VertexBuffer);
shape.Shape.VertexBufferIndex = (ushort)(resFile.Models[CurMdl].VertexBuffers.Count - 1);
SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
}
foreach (FMAT mat in model.materials.Values)
{
BfresSwitch.SetMaterial(mat, mat.Material);
resFile.Models[CurMdl].Materials.Add(mat.Material);
}
CurMdl++;
}
resFile.Models.Clear();
resFile.SkeletalAnims.Clear();
resFile.MaterialAnims.Clear();
resFile.SceneAnims.Clear();
resFile.ShapeAnims.Clear();
resFile.BoneVisibilityAnims.Clear();
int CurMdl = 0;
if (EditorRoot.Nodes.ContainsKey("FMDL"))
{
foreach (FMDL model in EditorRoot.Nodes["FMDL"].Nodes)
resFile.Models.Add(BfresSwitch.SetModel(model));
}
if (EditorRoot.Nodes.ContainsKey("FSKA"))
{
foreach (BfresSkeletonAnim ska in EditorRoot.Nodes["FSKA"].Nodes)
{
resFile.SkeletalAnims.Add(ska.SkeletalAnim);
}
}
if (EditorRoot.Nodes.ContainsKey("FMAA"))
{
foreach (FMAA fmaa in EditorRoot.Nodes["FMAA"].Nodes)
resFile.MaterialAnims.Add(fmaa.MaterialAnim);
}
if (EditorRoot.Nodes.ContainsKey("FBNV"))
{
foreach (FBNV fbnv in EditorRoot.Nodes["FBNV"].Nodes)
resFile.BoneVisibilityAnims.Add(fbnv.VisibilityAnim);
}
if (EditorRoot.Nodes.ContainsKey("FSHPA"))
{
foreach (FSHA fsha in EditorRoot.Nodes["FSHPA"].Nodes)
resFile.ShapeAnims.Add(fsha.ShapeAnim);
}
if (EditorRoot.Nodes.ContainsKey("FSCN"))
{
foreach (FSCN fscn in EditorRoot.Nodes["FSCN"].Nodes)
resFile.SceneAnims.Add(fscn.SceneAnim);
}
ErrorCheck();
@ -229,7 +230,7 @@ namespace FirstPlugin
}
}
private void SetShaderAssignAttributes(FMAT.ShaderAssign shd, FSHP shape)
public static void SetShaderAssignAttributes(FMAT.ShaderAssign shd, FSHP shape)
{
foreach (var att in shape.vertexAttributes)
{
@ -259,9 +260,9 @@ namespace FirstPlugin
}
}
bool ImportMissingTextures = false;
private void CheckMissingTextures(FSHP shape)
public static void CheckMissingTextures(FSHP shape)
{
bool ImportMissingTextures = false;
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
{
foreach (MatTexture tex in shape.GetMaterial().textures)

View File

@ -2,7 +2,7 @@
using Switch_Toolbox.Library;
using System.Windows.Forms;
using FirstPlugin;
using Syroot.NintenTools.NSW.Bfres;
namespace Bfres.Structs
{
@ -30,7 +30,16 @@ namespace Bfres.Structs
}
public void ExportAll(object sender, EventArgs args)
{
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
string folderPath = sfd.SelectedPath;
foreach (FBNV fbnv in Nodes)
{
string FileName = folderPath + '\\' + fbnv.Text + ".bfska";
((FBNV)fbnv).VisibilityAnim.Export(FileName, fbnv.GetResFile());
}
}
}
public void Clear(object sender, EventArgs args)
{
@ -47,4 +56,54 @@ namespace Bfres.Structs
FormLoader.LoadEditor(this, Text);
}
}
public class FBNV : TreeNodeCustom
{
public VisibilityAnim VisibilityAnim;
public FBNV()
{
ImageKey = "visibilityAnim";
SelectedImageKey = "visibilityAnim";
ContextMenu = new ContextMenu();
MenuItem export = new MenuItem("Export");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
MenuItem replace = new MenuItem("Replace");
ContextMenu.MenuItems.Add(replace);
replace.Click += Replace;
}
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Supported Formats|*.bfvis;";
sfd.FileName = Text;
sfd.DefaultExt = ".bfvis";
if (sfd.ShowDialog() == DialogResult.OK)
{
VisibilityAnim.Export(sfd.FileName, GetResFile());
}
}
private void Replace(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.bfvis;";
if (ofd.ShowDialog() == DialogResult.OK)
{
VisibilityAnim.Import(ofd.FileName);
}
VisibilityAnim.Name = Text;
}
public void Read(VisibilityAnim vis)
{
VisibilityAnim = vis;
}
}
}

View File

@ -59,6 +59,19 @@ namespace Bfres.Structs
{
public BFRESRender BFRESRender;
public MaterialAnim MaterialAnim;
public FMAA()
{
ImageKey = "materialAnim";
SelectedImageKey = "materialAnim";
ContextMenu = new ContextMenu();
MenuItem export = new MenuItem("Export");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
MenuItem replace = new MenuItem("Replace");
ContextMenu.MenuItems.Add(replace);
replace.Click += Replace;
}
public ResFile GetResFile()
{
@ -68,5 +81,28 @@ namespace Bfres.Structs
{
MaterialAnim = anim;
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Supported Formats|*.bfmaa;";
sfd.FileName = Text;
sfd.DefaultExt = ".bfska";
if (sfd.ShowDialog() == DialogResult.OK)
{
MaterialAnim.Export(sfd.FileName, GetResFile());
}
}
private void Replace(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.bfmaa;";
if (ofd.ShowDialog() == DialogResult.OK)
{
MaterialAnim.Import(ofd.FileName);
}
MaterialAnim.Name = Text;
}
}
}

View File

@ -69,7 +69,19 @@ namespace Bfres.Structs
public override void OnClick(TreeView treeView)
{
FormLoader.LoadMatEditor(this);
UpdateFMATEditor();
}
public void UpdateFMATEditor()
{
FMATEditor docked = (FMATEditor)LibraryGUI.Instance.GetContentDocked(new FMATEditor());
if (docked == null)
{
docked = new FMATEditor();
LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
}
docked.Text = Text;
docked.Dock = DockStyle.Fill;
docked.LoadMaterial(this);
}
public ResFile GetResFile()
{

View File

@ -18,7 +18,7 @@ namespace Bfres.Structs
public FmdlFolder()
{
Text = "Models";
Name = "FMDLFolder";
Name = "FMDL";
ContextMenu = new ContextMenu();
MenuItem import = new MenuItem("Import");

View File

@ -30,7 +30,16 @@ namespace Bfres.Structs
}
private void ExportAll(object sender, EventArgs args)
{
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
string folderPath = sfd.SelectedPath;
foreach (FSCN fscn in Nodes)
{
string FileName = folderPath + '\\' + fscn.Text + ".bfscn";
((FSCN)fscn).SceneAnim.Export(FileName, fscn.GetResFile());
}
}
}
private void Clear(object sender, EventArgs args)
{

View File

@ -2,6 +2,7 @@
using System.Windows.Forms;
using Switch_Toolbox.Library;
using FirstPlugin;
using Syroot.NintenTools.NSW.Bfres;
namespace Bfres.Structs
{
@ -27,13 +28,22 @@ namespace Bfres.Structs
{
}
private void ExportAll(object sender, EventArgs args)
public void ExportAll(object sender, EventArgs args)
{
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
string folderPath = sfd.SelectedPath;
foreach (FSHA fsha in Nodes)
{
string FileName = folderPath + '\\' + fsha.Text + ".bfshpa";
((FSHA)fsha).ShapeAnim.Export(FileName, fsha.GetResFile());
}
}
}
private void Clear(object sender, EventArgs args)
{
DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all objects? This cannot be undone!", "", MessageBoxButtons.YesNo);
DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all shape animations? This cannot be undone!", "", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
@ -45,4 +55,54 @@ namespace Bfres.Structs
FormLoader.LoadEditor(this, Text);
}
}
public class FSHA : TreeNodeCustom
{
public ShapeAnim ShapeAnim;
public FSHA()
{
ImageKey = "shapeAnimation";
SelectedImageKey = "shapeAnimation";
ContextMenu = new ContextMenu();
MenuItem export = new MenuItem("Export");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
MenuItem replace = new MenuItem("Replace");
ContextMenu.MenuItems.Add(replace);
replace.Click += Replace;
}
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Supported Formats|*.bfshpa;";
sfd.FileName = Text;
sfd.DefaultExt = ".bfshpa";
if (sfd.ShowDialog() == DialogResult.OK)
{
ShapeAnim.Export(sfd.FileName, GetResFile());
}
}
private void Replace(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.bfshpa;";
if (ofd.ShowDialog() == DialogResult.OK)
{
ShapeAnim.Import(ofd.FileName);
}
ShapeAnim.Name = Text;
}
public void Read(ShapeAnim shapeAnim)
{
ShapeAnim = shapeAnim;
}
}
}

View File

@ -134,7 +134,6 @@ namespace Bfres.Structs
ContextMenu.MenuItems.Add(rename);
rename.Click += Rename;
}
public FMATEditor editor;
public int ModelIndex; //For getting the model the shape is in
public VertexBuffer VertexBuffer;
@ -171,7 +170,19 @@ namespace Bfres.Structs
public override void OnClick(TreeView treeView)
{
FormLoader.LoadShapeEditor(this);
UpdateFSHPEditor();
}
public void UpdateFSHPEditor()
{
FSHPEditor docked = (FSHPEditor)LibraryGUI.Instance.GetContentDocked(new FSHPEditor());
if (docked == null)
{
docked = new FSHPEditor();
LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
}
docked.Text = Text;
docked.Dock = DockStyle.Fill;
docked.LoadObject((FMDL)Parent.Parent, this);
}
private void SmoothNormals(object sender, EventArgs args)
{
@ -288,7 +299,7 @@ namespace Bfres.Structs
}
private void OpenMaterialEditor(object sender, EventArgs args)
{
FormLoader.LoadMatEditor(GetMaterial());
GetMaterial().UpdateFMATEditor();
}
private void CalcTansBitans(object sender, EventArgs args)
{

View File

@ -33,7 +33,16 @@ namespace Bfres.Structs
}
public void ExportAll(object sender, EventArgs args)
{
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
string folderPath = sfd.SelectedPath;
foreach (BfresSkeletonAnim fska in Nodes)
{
string FileName = folderPath + '\\' + fska.Text + ".bfska";
((BfresSkeletonAnim)fska).SkeletalAnim.Export(FileName, fska.GetResFile());
}
}
}
private void Clear(object sender, EventArgs args)
{

View File

@ -71,7 +71,7 @@ namespace Bfres.Structs
{
node = new fsklNode();
node.Skeleton = skl;
BfresSwitch.SetSkeleton(node, skl, this);
BfresSwitch.ReadSkeleton(node, skl, this);
}
public FSKL(ResU.Skeleton skl)
{

View File

@ -107,9 +107,9 @@ namespace Bfres.Structs
public override void OnClick(TreeView treeView)
{
//If has models
if (Nodes.ContainsKey("FMDLFolder"))
if (Nodes.ContainsKey("FMDL"))
{
if (Nodes["FMDLFolder"].Nodes.ContainsKey("FshpFolder"))
if (Nodes["FMDL"].Nodes.ContainsKey("FshpFolder"))
{
}

View File

@ -17,6 +17,36 @@ namespace FirstPlugin
{
public static class BfresSwitch
{
public static Model SetModel(FMDL fmdl)
{
Model model = new Model();
int i = 0;
var duplicates = fmdl.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);
foreach (var shape in duplicates)
shape.Text += i++;
foreach (FSHP shape in fmdl.shapes)
{
BFRES.CheckMissingTextures(shape);
SetShape(shape, shape.Shape);
model.Shapes.Add(shape.Shape);
model.VertexBuffers.Add(shape.VertexBuffer);
shape.Shape.VertexBufferIndex = (ushort)(model.VertexBuffers.Count - 1);
BFRES.SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
}
foreach (FMAT mat in fmdl.materials.Values)
{
SetMaterial(mat, mat.Material);
model.Materials.Add(mat.Material);
}
return model;
}
public static void Read(BFRESRender renderer, ResFile resFile, TreeNode ResFileNode)
{
int CurMdl = 0;
@ -119,7 +149,6 @@ namespace FirstPlugin
}
return Shape;
}
public static void ReadShapesVertices(FSHP fshp, Shape shp, VertexBuffer vertexBuffer, FMDL model)
{
fshp.boundingBoxes.Clear();
@ -448,8 +477,7 @@ namespace FirstPlugin
}
return curve;
}
public static void SetSkeleton(this TreeNodeCustom skl, Skeleton skeleton, FSKL RenderableSkeleton)
public static void ReadSkeleton(this TreeNodeCustom skl, Skeleton skeleton, FSKL RenderableSkeleton)
{
if (skeleton.MatrixToBoneList == null)
skeleton.MatrixToBoneList = new List<ushort>();
@ -465,7 +493,7 @@ namespace FirstPlugin
foreach (Bone bone in skeleton.Bones)
{
BfresBone STBone = new BfresBone(RenderableSkeleton);
SetBone(STBone, bone);
ReadBone(STBone, bone);
RenderableSkeleton.bones.Add(STBone);
}
RenderableSkeleton.update();
@ -477,7 +505,7 @@ namespace FirstPlugin
Runtime.abstractGlDrawables.Add(RenderableSkeleton);
}
public static void SetBone(this BfresBone bone, Bone bn)
public static void ReadBone(this BfresBone bone, Bone bn)
{
bone.Bone = bn;
bone.Text = bn.Name;
@ -928,7 +956,6 @@ namespace FirstPlugin
mat.ShaderAssign.AttribAssigns.Add(att.Value);
}
}
public static void WriteExternalFiles(ResFile resFile, TreeNode EditorRoot)
{
resFile.ExternalFiles.Clear();

View File

@ -727,30 +727,20 @@ namespace FirstPlugin
}
public override void OnClick(TreeView treeView)
{
if (LibraryGUI.Instance.dockContent != null && !EditorIsActive(LibraryGUI.Instance.dockContent))
{
BNTXEditor BNTXEditor = new BNTXEditor();
BNTXEditor.Text = Text;
BNTXEditor.Dock = DockStyle.Fill;
BNTXEditor.LoadProperty(this);
LibraryGUI.Instance.LoadDockContent(BNTXEditor, PluginRuntime.FSHPDockState);
}
UpdateBNTXEditor();
}
public bool EditorIsActive(DockContent dock)
public void UpdateBNTXEditor()
{
foreach (Control ctrl in dock.Controls)
BNTXEditor docked = (BNTXEditor)LibraryGUI.Instance.GetContentDocked(new BNTXEditor());
if (docked == null)
{
if (ctrl is BNTXEditor)
{
dock.Text = Text;
((BNTXEditor)ctrl).LoadProperty(this);
return true;
}
docked = new BNTXEditor();
LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
}
return false;
docked.Text = Text;
docked.Dock = DockStyle.Fill;
docked.LoadProperty(this);
}
public BRTI_Texture LoadOpenGLTexture()
{
if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized)
@ -1121,8 +1111,7 @@ namespace FirstPlugin
}
Texture.Name = Text;
UpdateBfresTextureMapping();
//LibraryGUI.Instance.LoadDockContent(BNTXEditor);
UpdateBNTXEditor();
}
}
private void UpdateBfresTextureMapping()

View File

@ -69,23 +69,5 @@ namespace FirstPlugin
}
return false;
}
public static void LoadMatEditor(FMAT mat)
{
FMATEditor editor = new FMATEditor();
editor.Text = mat.Text;
editor.Dock = DockStyle.Fill;
editor.LoadMaterial(mat);
LibraryGUI.Instance.LoadDockContent(editor, PluginRuntime.FSHPDockState);
}
public static void LoadShapeEditor(FSHP fshp)
{
FSHPEditor BfresProperties = new FSHPEditor();
BfresProperties.Text = fshp.Text;
BfresProperties.Dock = DockStyle.Fill;
BfresProperties.LoadObject((FMDL)fshp.Parent.Parent, fshp);
LibraryGUI.Instance.LoadDockContent(BfresProperties, PluginRuntime.FSHPDockState);
}
}
}

View File

@ -29,12 +29,12 @@ namespace Switch_Toolbox.Library
}
public UserControl GetContentDocked(UserControl control)
{
foreach (DockContent dockContent in dockPanel.Contents)
{
foreach (Control ctrl in dockContent.Controls)
if (ctrl.GetType() == control.GetType())
return (UserControl)ctrl;
}
if (dockContent == null)
return null;
foreach (Control ctrl in dockContent.Controls)
if (ctrl.GetType() == control.GetType())
return (UserControl)ctrl;
return null;
}
public DockContent GetContentDocked(DockContent DockContent)