1
0
mirror of synced 2025-01-19 09:17:30 +01:00

Update library and clean up some things

This commit is contained in:
KillzXGaming 2018-11-22 19:40:36 -05:00
parent 898003ddb2
commit 4e1c4a5266
22 changed files with 5860 additions and 153 deletions

View File

@ -145,12 +145,14 @@ namespace FirstPlugin
} }
private void SaveSwitch(MemoryStream mem) private void SaveSwitch(MemoryStream mem)
{ {
var resFile = bfres.ResFileNode.resFile;
int CurMdl = 0; int CurMdl = 0;
foreach (FMDL model in bfres.models) foreach (FMDL model in bfres.models)
{ {
bfres.resFile.Models[CurMdl].Shapes.Clear(); resFile.Models[CurMdl].Shapes.Clear();
bfres.resFile.Models[CurMdl].VertexBuffers.Clear(); resFile.Models[CurMdl].VertexBuffers.Clear();
bfres.resFile.Models[CurMdl].Materials.Clear(); resFile.Models[CurMdl].Materials.Clear();
int i = 0; int i = 0;
var duplicates = model.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c); var duplicates = model.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);
@ -162,43 +164,45 @@ namespace FirstPlugin
CheckMissingTextures(shape); CheckMissingTextures(shape);
BfresSwitch.SetShape(shape, shape.Shape); BfresSwitch.SetShape(shape, shape.Shape);
bfres.resFile.Models[CurMdl].Shapes.Add(shape.Shape); resFile.Models[CurMdl].Shapes.Add(shape.Shape);
bfres.resFile.Models[CurMdl].VertexBuffers.Add(shape.VertexBuffer); resFile.Models[CurMdl].VertexBuffers.Add(shape.VertexBuffer);
shape.Shape.VertexBufferIndex = (ushort)(bfres.resFile.Models[CurMdl].VertexBuffers.Count - 1); shape.Shape.VertexBufferIndex = (ushort)(resFile.Models[CurMdl].VertexBuffers.Count - 1);
SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape); SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
} }
foreach (FMAT mat in model.materials.Values) foreach (FMAT mat in model.materials.Values)
{ {
BfresSwitch.SetMaterial(mat, mat.Material); BfresSwitch.SetMaterial(mat, mat.Material);
bfres.resFile.Models[CurMdl].Materials.Add(mat.Material); resFile.Models[CurMdl].Materials.Add(mat.Material);
} }
CurMdl++; CurMdl++;
} }
bfres.resFile.SkeletalAnims.Clear(); resFile.SkeletalAnims.Clear();
if (EditorRoot.Nodes.ContainsKey("FSKA")) if (EditorRoot.Nodes.ContainsKey("FSKA"))
{ {
foreach (BfresSkeletonAnim ska in EditorRoot.Nodes["FSKA"].Nodes) foreach (BfresSkeletonAnim ska in EditorRoot.Nodes["FSKA"].Nodes)
{ {
bfres.resFile.SkeletalAnims.Add(ska.SkeletalAnim); resFile.SkeletalAnims.Add(ska.SkeletalAnim);
} }
} }
ErrorCheck(); ErrorCheck();
BfresSwitch.WriteExternalFiles(bfres.resFile, EditorRoot); BfresSwitch.WriteExternalFiles(resFile, EditorRoot);
bfres.resFile.Save(mem); resFile.Save(mem);
} }
private void SaveWiiU(MemoryStream mem) private void SaveWiiU(MemoryStream mem)
{ {
bfres.resFileU.Save(mem); var resFileU = bfres.ResFileNode.resFileU;
resFileU.Save(mem);
int CurMdl = 0; int CurMdl = 0;
foreach (FMDL model in bfres.models) foreach (FMDL model in bfres.models)
{ {
bfres.resFileU.Models[CurMdl].Shapes.Clear(); resFileU.Models[CurMdl].Shapes.Clear();
bfres.resFileU.Models[CurMdl].VertexBuffers.Clear(); resFileU.Models[CurMdl].VertexBuffers.Clear();
bfres.resFileU.Models[CurMdl].Materials.Clear(); resFileU.Models[CurMdl].Materials.Clear();
int i = 0; int i = 0;
var duplicates = model.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c); var duplicates = model.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);
@ -210,16 +214,16 @@ namespace FirstPlugin
CheckMissingTextures(shape); CheckMissingTextures(shape);
BfresWiiU.SetShape(shape, shape.ShapeU); BfresWiiU.SetShape(shape, shape.ShapeU);
bfres.resFileU.Models[CurMdl].Shapes.Add(shape.Text, shape.ShapeU); resFileU.Models[CurMdl].Shapes.Add(shape.Text, shape.ShapeU);
bfres.resFileU.Models[CurMdl].VertexBuffers.Add(shape.VertexBufferU); resFileU.Models[CurMdl].VertexBuffers.Add(shape.VertexBufferU);
shape.ShapeU.VertexBufferIndex = (ushort)(bfres.resFileU.Models[CurMdl].VertexBuffers.Count - 1); shape.ShapeU.VertexBufferIndex = (ushort)(resFileU.Models[CurMdl].VertexBuffers.Count - 1);
SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape); SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
} }
foreach (FMAT mat in model.materials.Values) foreach (FMAT mat in model.materials.Values)
{ {
BfresWiiU.SetMaterial(mat, mat.MaterialU); BfresWiiU.SetMaterial(mat, mat.MaterialU);
bfres.resFileU.Models[CurMdl].Materials.Add(mat.Text, mat.MaterialU); resFileU.Models[CurMdl].Materials.Add(mat.Text, mat.MaterialU);
} }
CurMdl++; CurMdl++;
} }

View File

@ -37,7 +37,16 @@ namespace Bfres.Structs
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
foreach (var ext in Nodes)
{
if (ext is BinaryTextureContainer)
{
PluginRuntime.bntxContainers.Remove((BinaryTextureContainer)ext);
}
}
Nodes.Clear(); Nodes.Clear();
Viewport.Instance.Refresh();
} }
} }
public override void OnClick(TreeView treeView) public override void OnClick(TreeView treeView)

View File

@ -37,7 +37,7 @@ namespace Bfres.Structs
foreach (FMAA fmaa in Nodes) foreach (FMAA fmaa in Nodes)
{ {
string FileName = folderPath + '\\' + fmaa.Text + ".bfmaa"; string FileName = folderPath + '\\' + fmaa.Text + ".bfmaa";
((FMAA)fmaa).MaterialAnim.Export(FileName, fmaa.BFRESRender.resFile); ((FMAA)fmaa).MaterialAnim.Export(FileName, fmaa.GetResFile());
} }
} }
@ -62,6 +62,10 @@ namespace Bfres.Structs
public BFRESRender BFRESRender; public BFRESRender BFRESRender;
public MaterialAnim MaterialAnim; public MaterialAnim MaterialAnim;
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
}
public void Read(MaterialAnim anim) public void Read(MaterialAnim anim)
{ {
MaterialAnim = anim; MaterialAnim = anim;

View File

@ -65,13 +65,26 @@ namespace Bfres.Structs
rename.Click += Rename; rename.Click += Rename;
} }
public BFRESRender BFRESRender;
public bool Enabled = true; public bool Enabled = true;
public override void OnClick(TreeView treeView) public override void OnClick(TreeView treeView)
{ {
FormLoader.LoadMatEditor(this); FormLoader.LoadMatEditor(this);
} }
public ResFile GetResFile()
{
//ResourceFile -> FMDL -> Material Folder -> this
return ((FMDL)Parent.Parent).GetResFile();
}
public ResU.ResFile GetResFileU()
{
return ((FMDL)Parent.Parent).GetResFileU();
}
public void UpdateTextureMaps()
{
((ResourceFile)Parent.Parent.Parent.Parent).BFRESRender.UpdateSingleMaterialTextureMaps(this);
}
public void SetActiveGame() public void SetActiveGame()
{ {
@ -115,7 +128,7 @@ namespace Bfres.Structs
if (sfd.ShowDialog() == DialogResult.OK) if (sfd.ShowDialog() == DialogResult.OK)
{ {
Material.Export(sfd.FileName, BFRESRender.resFile); Material.Export(sfd.FileName, GetResFile());
} }
} }
private void Replace(object sender, EventArgs args) private void Replace(object sender, EventArgs args)

View File

@ -60,10 +60,28 @@ namespace Bfres.Structs
{ {
public List<FSHP> shapes = new List<FSHP>(); public List<FSHP> shapes = new List<FSHP>();
public Dictionary<string, FMAT> materials = new Dictionary<string, FMAT>(); public Dictionary<string, FMAT> materials = new Dictionary<string, FMAT>();
public BFRESRender BFRESRender;
public Model Model; public Model Model;
public ResU.Model ModelU; public ResU.Model ModelU;
public ResFile GetResFile()
{
//ResourceFile -> FMDL -> Material Folder -> this
return ((ResourceFile)Parent.Parent).resFile;
}
public ResU.ResFile GetResFileU()
{
return ((ResourceFile)Parent.Parent).resFileU;
}
public void UpdateVertexData()
{
((ResourceFile)Parent.Parent).BFRESRender.UpdateVertexData();
}
public List<FMDL> GetModelList()
{
return ((ResourceFile)Parent.Parent).BFRESRender.models;
}
public FMDL() public FMDL()
{ {
ImageKey = "model"; ImageKey = "model";
@ -105,7 +123,7 @@ namespace Bfres.Structs
shp.SaveVertexBuffer(); shp.SaveVertexBuffer();
} }
BFRESRender.UpdateVertexData(); UpdateVertexData();
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
private void RecalculateNormals(object sender, EventArgs args) private void RecalculateNormals(object sender, EventArgs args)
@ -119,7 +137,7 @@ namespace Bfres.Structs
shp.SaveVertexBuffer(); shp.SaveVertexBuffer();
} }
BFRESRender.UpdateVertexData(); UpdateVertexData();
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
private void Rename(object sender, EventArgs args) private void Rename(object sender, EventArgs args)
@ -181,13 +199,13 @@ namespace Bfres.Structs
shp.SaveVertexBuffer(); shp.SaveVertexBuffer();
} }
BFRESRender.UpdateVertexData(); UpdateVertexData();
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
public void CopyMaterial(FMAT selectedMaterial) public void CopyMaterial(FMAT selectedMaterial)
{ {
CopyMaterialMenu menu = new CopyMaterialMenu(); CopyMaterialMenu menu = new CopyMaterialMenu();
menu.LoadMaterials(selectedMaterial.Text, BFRESRender.models); menu.LoadMaterials(selectedMaterial.Text, GetModelList());
if (menu.ShowDialog() == DialogResult.OK) if (menu.ShowDialog() == DialogResult.OK)
{ {
foreach (TreeNode mdl in menu.materialTreeView.Nodes) foreach (TreeNode mdl in menu.materialTreeView.Nodes)
@ -281,7 +299,7 @@ namespace Bfres.Structs
switch (ext) switch (ext)
{ {
case ".bfmdl": case ".bfmdl":
Model.Export(sfd.FileName, BFRESRender.resFile); Model.Export(sfd.FileName, GetResFile());
break; break;
case ".csv": case ".csv":
CsvModel csv = new CsvModel(); CsvModel csv = new CsvModel();
@ -360,7 +378,6 @@ namespace Bfres.Structs
FSHP shapeS = new FSHP(); FSHP shapeS = new FSHP();
shapeS.Shape = shpS; shapeS.Shape = shpS;
shapeS.BFRESRender = BFRESRender;
BfresSwitch.ReadShapesVertices(shapeS, shpS, vertexBuffer, this); BfresSwitch.ReadShapesVertices(shapeS, shpS, vertexBuffer, this);
shapes.Add(shapeS); shapes.Add(shapeS);
Nodes["FshpFolder"].Nodes.Add(shapeS); Nodes["FshpFolder"].Nodes.Add(shapeS);
@ -370,7 +387,7 @@ namespace Bfres.Structs
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
shapes.Clear(); shapes.Clear();
Model mdl = new Model(); Model mdl = new Model();
mdl.Import(FileName, BFRESRender.resFile); mdl.Import(FileName, GetResFile());
mdl.Name = Text; mdl.Name = Text;
shapes.Clear(); shapes.Clear();
Nodes["FshpFolder"].Nodes.Clear(); Nodes["FshpFolder"].Nodes.Clear();
@ -417,7 +434,6 @@ namespace Bfres.Structs
shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex)); shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex));
shape.SaveShape(); shape.SaveShape();
shape.SaveVertexBuffer(); shape.SaveVertexBuffer();
shape.BFRESRender = BFRESRender;
shape.BoneIndices = new List<ushort>(); shape.BoneIndices = new List<ushort>();
Nodes["FshpFolder"].Nodes.Add(shape); Nodes["FshpFolder"].Nodes.Add(shape);
@ -574,7 +590,6 @@ namespace Bfres.Structs
shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex)); shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex));
shape.SaveShape(); shape.SaveShape();
shape.SaveVertexBuffer(); shape.SaveVertexBuffer();
shape.BFRESRender = BFRESRender;
shape.BoneIndices = new List<ushort>(); shape.BoneIndices = new List<ushort>();
List<string> keyList = shapes.Select(o => o.Text).ToList(); List<string> keyList = shapes.Select(o => o.Text).ToList();
@ -587,7 +602,7 @@ namespace Bfres.Structs
} }
break; break;
} }
BFRESRender.UpdateVertexData(); UpdateVertexData();
} }
public FMAT GetMaterial(int index) public FMAT GetMaterial(int index)
{ {
@ -611,7 +626,6 @@ namespace Bfres.Structs
mat.Material = new Material(); mat.Material = new Material();
mat.Material.Import(FileName); mat.Material.Import(FileName);
mat.ReadMaterial(mat.Material); mat.ReadMaterial(mat.Material);
mat.BFRESRender = BFRESRender;
mat.Text = mat.Material.Name; mat.Text = mat.Material.Name;
materials.Add(mat.Text, mat); materials.Add(mat.Text, mat);

View File

@ -40,17 +40,6 @@ namespace Bfres.Structs
Nodes.Clear(); Nodes.Clear();
} }
} }
public void LoadAnimations(ResFile resFile, BFRESRender BFRESRender)
{
foreach (var scn in resFile.SceneAnims)
{
FSCN sceneAnim = new FSCN();
sceneAnim.Text = scn.Name;
sceneAnim.BFRESRender = BFRESRender;
sceneAnim.Read(scn);
Nodes.Add(sceneAnim);
}
}
public override void OnClick(TreeView treeView) public override void OnClick(TreeView treeView)
{ {
@ -61,8 +50,6 @@ namespace Bfres.Structs
public class FSCN : TreeNodeCustom public class FSCN : TreeNodeCustom
{ {
public SceneAnim SceneAnim; public SceneAnim SceneAnim;
public BFRESRender BFRESRender;
public FSCN() public FSCN()
{ {
ImageKey = "skeletonAnimation"; ImageKey = "skeletonAnimation";
@ -77,6 +64,11 @@ namespace Bfres.Structs
replace.Click += Replace; replace.Click += Replace;
} }
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args) private void Export(object sender, EventArgs args)
{ {
SaveFileDialog sfd = new SaveFileDialog(); SaveFileDialog sfd = new SaveFileDialog();
@ -86,7 +78,7 @@ namespace Bfres.Structs
if (sfd.ShowDialog() == DialogResult.OK) if (sfd.ShowDialog() == DialogResult.OK)
{ {
SceneAnim.Export(sfd.FileName, BFRESRender.resFile); SceneAnim.Export(sfd.FileName, GetResFile());
} }
} }
private void Replace(object sender, EventArgs args) private void Replace(object sender, EventArgs args)

View File

@ -41,7 +41,7 @@ namespace Bfres.Structs
{ {
Nodes.Clear(); Nodes.Clear();
((FMDL)Parent).shapes.Clear(); ((FMDL)Parent).shapes.Clear();
((FMDL)Parent).BFRESRender.UpdateVertexData(); ((FMDL)Parent).UpdateVertexData();
} }
} }
private void ExportAll(object sender, EventArgs args) private void ExportAll(object sender, EventArgs args)
@ -134,8 +134,6 @@ namespace Bfres.Structs
ContextMenu.MenuItems.Add(rename); ContextMenu.MenuItems.Add(rename);
rename.Click += Rename; rename.Click += Rename;
} }
public BFRESRender BFRESRender;
public FMATEditor editor; public FMATEditor editor;
public int ModelIndex; //For getting the model the shape is in public int ModelIndex; //For getting the model the shape is in
@ -144,6 +142,24 @@ namespace Bfres.Structs
public ResU.VertexBuffer VertexBufferU; public ResU.VertexBuffer VertexBufferU;
public ResU.Shape ShapeU; public ResU.Shape ShapeU;
public ResFile GetResFile()
{
//ResourceFile -> FMDL -> Material Folder -> this
return ((FMDL)Parent.Parent).GetResFile();
}
public ResU.ResFile GetResFileU()
{
return ((FMDL)Parent.Parent).GetResFileU();
}
public void UpdateVertexData()
{
((FMDL)Parent.Parent).UpdateVertexData();
}
public List<FMDL> GetModelList()
{
return ((FMDL)Parent.Parent).GetModelList();
}
public FMAT GetMaterial() public FMAT GetMaterial()
{ {
return ((FMDL)Parent.Parent).materials.Values.ElementAt(MaterialIndex); return ((FMDL)Parent.Parent).materials.Values.ElementAt(MaterialIndex);
@ -162,7 +178,7 @@ namespace Bfres.Structs
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
SmoothNormals(); SmoothNormals();
SaveVertexBuffer(); SaveVertexBuffer();
BFRESRender.UpdateVertexData(); UpdateVertexData();
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
private void RecalculateNormals(object sender, EventArgs args) private void RecalculateNormals(object sender, EventArgs args)
@ -170,7 +186,7 @@ namespace Bfres.Structs
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
CalculateNormals(); CalculateNormals();
SaveVertexBuffer(); SaveVertexBuffer();
BFRESRender.UpdateVertexData(); UpdateVertexData();
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
private void Rename(object sender, EventArgs args) private void Rename(object sender, EventArgs args)
@ -190,7 +206,7 @@ namespace Bfres.Structs
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
((FMDL)Parent.Parent).shapes.Remove(this); ((FMDL)Parent.Parent).shapes.Remove(this);
((FMDL)Parent.Parent).BFRESRender.UpdateVertexData(); ((FMDL)Parent.Parent).UpdateVertexData();
Parent.Nodes.Remove(this); Parent.Nodes.Remove(this);
} }
} }
@ -320,7 +336,7 @@ namespace Bfres.Structs
CalculateTangentBitangent(); CalculateTangentBitangent();
SaveVertexBuffer(); SaveVertexBuffer();
BFRESRender.UpdateVertexData(); UpdateVertexData();
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
public bool HasUV0() public bool HasUV0()
@ -345,7 +361,7 @@ namespace Bfres.Structs
FlipUvsVertical(); FlipUvsVertical();
SaveVertexBuffer(); SaveVertexBuffer();
BFRESRender.UpdateVertexData(); UpdateVertexData();
} }
public void FlipUvsHorizontal(object sender, EventArgs args) public void FlipUvsHorizontal(object sender, EventArgs args)
{ {
@ -357,7 +373,7 @@ namespace Bfres.Structs
FlipUvsHorizontal(); FlipUvsHorizontal();
SaveVertexBuffer(); SaveVertexBuffer();
BFRESRender.UpdateVertexData(); UpdateVertexData();
} }
public void ExportMaterials(object sender, EventArgs args) public void ExportMaterials(object sender, EventArgs args)
{ {
@ -368,7 +384,7 @@ namespace Bfres.Structs
if (sfd.ShowDialog() == DialogResult.OK) if (sfd.ShowDialog() == DialogResult.OK)
{ {
GetMaterial().Material.Export(sfd.FileName, BFRESRender.resFile); GetMaterial().Material.Export(sfd.FileName, GetResFile());
} }
} }
public void ReplaceMaterials(object sender, EventArgs args) public void ReplaceMaterials(object sender, EventArgs args)
@ -414,7 +430,7 @@ namespace Bfres.Structs
} }
public void ExportBinaryObject(string FileName) public void ExportBinaryObject(string FileName)
{ {
Shape.Export(FileName, BFRESRender.resFile); Shape.Export(FileName, GetResFile());
} }
public void Replace(object sender, EventArgs args) public void Replace(object sender, EventArgs args)
{ {
@ -438,7 +454,7 @@ namespace Bfres.Structs
shp.Import(ofd.FileName, VertexBuffer); shp.Import(ofd.FileName, VertexBuffer);
shp.Name = Text; shp.Name = Text;
shp.MaterialIndex = (ushort)MaterialIndex; shp.MaterialIndex = (ushort)MaterialIndex;
BfresSwitch.ReadShapesVertices(this, shp, VertexBuffer, BFRESRender.models[ModelIndex]); BfresSwitch.ReadShapesVertices(this, shp, VertexBuffer, GetModelList()[ModelIndex]);
break; break;
default: default:
AssimpData assimp = new AssimpData(); AssimpData assimp = new AssimpData();
@ -474,7 +490,7 @@ namespace Bfres.Structs
} }
break; break;
} }
BFRESRender.UpdateVertexData(); UpdateVertexData();
} }
} }
public void CreateIndexList(GenericObject ob, FMDL mdl = null) public void CreateIndexList(GenericObject ob, FMDL mdl = null)

View File

@ -60,7 +60,6 @@ namespace Bfres.Structs
ZROT = 0x28, ZROT = 0x28,
} }
public SkeletalAnim SkeletalAnim; public SkeletalAnim SkeletalAnim;
public BFRESRender BFRESRender;
public BfresSkeletonAnim() public BfresSkeletonAnim()
{ {
@ -90,6 +89,11 @@ namespace Bfres.Structs
ContextMenu.MenuItems.Add(replace); ContextMenu.MenuItems.Add(replace);
replace.Click += Replace; replace.Click += Replace;
} }
public ResFile GetResFile()
{
//ResourceFile -> FMDL -> Material Folder -> this
return ((ResourceFile)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args) private void Export(object sender, EventArgs args)
{ {
SaveFileDialog sfd = new SaveFileDialog(); SaveFileDialog sfd = new SaveFileDialog();
@ -99,7 +103,7 @@ namespace Bfres.Structs
if (sfd.ShowDialog() == DialogResult.OK) if (sfd.ShowDialog() == DialogResult.OK)
{ {
SkeletalAnim.Export(sfd.FileName, BFRESRender.resFile); SkeletalAnim.Export(sfd.FileName, GetResFile());
} }
} }
private void Replace(object sender, EventArgs args) private void Replace(object sender, EventArgs args)

View File

@ -43,7 +43,7 @@ namespace Bfres.Structs
if (sfd.ShowDialog() == DialogResult.OK) if (sfd.ShowDialog() == DialogResult.OK)
{ {
Skeleton.Export(sfd.FileName, BFRESRender.resFile); Skeleton.Export(sfd.FileName, ((FMDL)Parent).GetResFile());
} }
} }
public void Replace(object sender, EventArgs args) public void Replace(object sender, EventArgs args)
@ -58,12 +58,10 @@ namespace Bfres.Structs
Skeleton.Import(ofd.FileName); Skeleton.Import(ofd.FileName);
} }
} }
public override void OnClick(TreeView treeView) public override void OnClick(TreeView treeView)
{ {
} }
} }
public FSKL() public FSKL()
{ {
@ -107,6 +105,11 @@ namespace Bfres.Structs
ContextMenu.MenuItems.Add(replace); ContextMenu.MenuItems.Add(replace);
replace.Click += Replace; replace.Click += Replace;
} }
public ResFile GetResFile()
{
//ResourceFile -> FMDL -> Material Folder -> this
return ((FMDL)Parent.Parent).GetResFile();
}
public void Export(object sender, EventArgs args) public void Export(object sender, EventArgs args)
{ {
SaveFileDialog sfd = new SaveFileDialog(); SaveFileDialog sfd = new SaveFileDialog();
@ -116,7 +119,7 @@ namespace Bfres.Structs
if (sfd.ShowDialog() == DialogResult.OK) if (sfd.ShowDialog() == DialogResult.OK)
{ {
Bone.Export(sfd.FileName, BFRESRender.resFile); Bone.Export(sfd.FileName, GetResFile());
} }
} }
public void Replace(object sender, EventArgs args) public void Replace(object sender, EventArgs args)

View File

@ -31,6 +31,9 @@ namespace Bfres.Structs
{ {
public BFRESRender BFRESRender; public BFRESRender BFRESRender;
public ResFile resFile = null;
public ResU.ResFile resFileU = null;
public TreeNode TextureFolder = new TreeNode("Textures"); public TreeNode TextureFolder = new TreeNode("Textures");
public ResourceFile(IFileFormat handler) public ResourceFile(IFileFormat handler)
{ {
@ -116,44 +119,46 @@ namespace Bfres.Structs
BFRESRender.UpdateVertexData(); BFRESRender.UpdateVertexData();
} }
} }
public void Load(ResU.ResFile resFile) public void Load(ResU.ResFile res)
{ {
Text = resFile.Name; resFileU = res;
if (resFile.Models.Count > 0) Text = resFileU.Name;
if (resFileU.Models.Count > 0)
Nodes.Add(new FmdlFolder()); Nodes.Add(new FmdlFolder());
if (resFile.Textures.Count > 0) if (resFileU.Textures.Count > 0)
AddFTEXTextures(resFile); AddFTEXTextures(resFileU);
if (resFile.SkeletalAnims.Count > 0) if (resFileU.SkeletalAnims.Count > 0)
AddSkeletonAnims(resFile); AddSkeletonAnims(resFileU);
if (resFile.ShaderParamAnims.Count > 0) if (resFileU.ShaderParamAnims.Count > 0)
Nodes.Add(new FshuFolder()); Nodes.Add(new FshuFolder());
if (resFile.ColorAnims.Count > 0) if (resFileU.ColorAnims.Count > 0)
Nodes.Add(new FshuColorFolder()); Nodes.Add(new FshuColorFolder());
if (resFile.TexSrtAnims.Count > 0) if (resFileU.TexSrtAnims.Count > 0)
Nodes.Add(new TexSrtFolder()); Nodes.Add(new TexSrtFolder());
if (resFile.TexPatternAnims.Count > 0) if (resFileU.TexPatternAnims.Count > 0)
Nodes.Add(new TexPatFolder()); Nodes.Add(new TexPatFolder());
if (resFile.ShapeAnims.Count > 0) if (resFileU.ShapeAnims.Count > 0)
Nodes.Add(new FshpaFolder()); Nodes.Add(new FshpaFolder());
if (resFile.BoneVisibilityAnims.Count > 0) if (resFileU.BoneVisibilityAnims.Count > 0)
Nodes.Add(new FbnvFolder()); Nodes.Add(new FbnvFolder());
if (resFile.SceneAnims.Count > 0) if (resFileU.SceneAnims.Count > 0)
Nodes.Add(new FscnFolder()); Nodes.Add(new FscnFolder());
if (resFile.ExternalFiles.Count > 0) if (resFileU.ExternalFiles.Count > 0)
Nodes.Add(new EmbeddedFilesFolder()); Nodes.Add(new EmbeddedFilesFolder());
foreach (var anim in resFile.ShaderParamAnims) foreach (var anim in resFileU.ShaderParamAnims)
Nodes["FSHA"].Nodes.Add(anim.Key); Nodes["FSHA"].Nodes.Add(anim.Key);
foreach (var anim in resFile.ColorAnims) foreach (var anim in resFileU.ColorAnims)
Nodes["FSHAColor"].Nodes.Add(anim.Key); Nodes["FSHAColor"].Nodes.Add(anim.Key);
foreach (var anim in resFile.TexSrtAnims) foreach (var anim in resFileU.TexSrtAnims)
Nodes["TEXSRT"].Nodes.Add(anim.Key); Nodes["TEXSRT"].Nodes.Add(anim.Key);
foreach (var anim in resFile.TexPatternAnims) foreach (var anim in resFileU.TexPatternAnims)
Nodes["TEXPAT"].Nodes.Add(anim.Key); Nodes["TEXPAT"].Nodes.Add(anim.Key);
int ext = 0; int ext = 0;
foreach (var extfile in resFile.ExternalFiles) foreach (var extfile in resFileU.ExternalFiles)
{ {
string Name = extfile.Key; string Name = extfile.Key;
@ -172,8 +177,10 @@ namespace Bfres.Structs
ext++; ext++;
} }
} }
public void Load(ResFile resFile) public void Load(ResFile res)
{ {
resFile = res;
Text = resFile.Name; Text = resFile.Name;
UpdateTree(resFile); UpdateTree(resFile);
@ -214,9 +221,9 @@ namespace Bfres.Structs
private void NewTextureFile(object sender, EventArgs args) private void NewTextureFile(object sender, EventArgs args)
{ {
string Name = "textures"; string Name = "textures";
for (int i = 0; i < BFRESRender.resFile.ExternalFiles.Count; i++) for (int i = 0; i < resFile.ExternalFiles.Count; i++)
{ {
if (BFRESRender.resFile.ExternalFileDict.GetKey(i) == Name) if (resFile.ExternalFileDict.GetKey(i) == Name)
Name = Name + i; Name = Name + i;
} }
if (!Nodes.ContainsKey("EXT")) if (!Nodes.ContainsKey("EXT"))
@ -225,7 +232,7 @@ namespace Bfres.Structs
} }
BNTX bntx = new BNTX(); BNTX bntx = new BNTX();
bntx.Data = new byte[0]; bntx.Data = new byte[0];
BinaryTextureContainer bntxTreeNode = new BinaryTextureContainer(new byte[0], "textures", BFRESRender.resFile.Name); BinaryTextureContainer bntxTreeNode = new BinaryTextureContainer(new byte[0], "textures", resFile.Name);
Nodes["EXT"].Nodes.Add(bntxTreeNode); Nodes["EXT"].Nodes.Add(bntxTreeNode);
} }
@ -288,7 +295,6 @@ namespace Bfres.Structs
foreach (ResU.SkeletalAnim ska in resFile.SkeletalAnims.Values) foreach (ResU.SkeletalAnim ska in resFile.SkeletalAnims.Values)
{ {
BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name); BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name);
skeletonAnim.BFRESRender = BFRESRender;
skeletonAnim.Read(ska, resFile); skeletonAnim.Read(ska, resFile);
fksaFolder.Nodes.Add(skeletonAnim); fksaFolder.Nodes.Add(skeletonAnim);
} }
@ -300,7 +306,6 @@ namespace Bfres.Structs
foreach (SkeletalAnim ska in resFile.SkeletalAnims) foreach (SkeletalAnim ska in resFile.SkeletalAnims)
{ {
BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name); BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name);
skeletonAnim.BFRESRender = BFRESRender;
skeletonAnim.Read(ska, resFile); skeletonAnim.Read(ska, resFile);
fksaFolder.Nodes.Add(skeletonAnim); fksaFolder.Nodes.Add(skeletonAnim);
} }
@ -318,7 +323,6 @@ namespace Bfres.Structs
{ {
FSCN sceneAnim = new FSCN(); FSCN sceneAnim = new FSCN();
sceneAnim.Text = scn.Name; sceneAnim.Text = scn.Name;
sceneAnim.BFRESRender = BFRESRender;
sceneAnim.Read(scn); sceneAnim.Read(scn);
fscnFolder.Nodes.Add(sceneAnim); fscnFolder.Nodes.Add(sceneAnim);
} }

View File

@ -28,13 +28,11 @@ namespace FirstPlugin
model.Nodes.Add(model.Skeleton.node); model.Nodes.Add(model.Skeleton.node);
model.Skeleton.reset(); model.Skeleton.reset();
model.Skeleton.update(); model.Skeleton.update();
model.BFRESRender = renderer;
model.Skeleton.node.BFRESRender = renderer; model.Skeleton.node.BFRESRender = renderer;
model.Model = mdl; model.Model = mdl;
foreach (Material mat in mdl.Materials) foreach (Material mat in mdl.Materials)
{ {
FMAT FMAT = new FMAT(); FMAT FMAT = new FMAT();
FMAT.BFRESRender = renderer;
FMAT.Text = mat.Name; FMAT.Text = mat.Name;
FMAT.ReadMaterial(mat); FMAT.ReadMaterial(mat);
model.Nodes[1].Nodes.Add(FMAT); model.Nodes[1].Nodes.Add(FMAT);
@ -45,7 +43,6 @@ namespace FirstPlugin
VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex]; VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex];
Material material = mdl.Materials[shp.MaterialIndex]; Material material = mdl.Materials[shp.MaterialIndex];
FSHP mesh = new FSHP(); FSHP mesh = new FSHP();
mesh.BFRESRender = renderer;
mesh.ModelIndex = CurMdl; mesh.ModelIndex = CurMdl;
ReadShapesVertices(mesh, shp, vertexBuffer, model); ReadShapesVertices(mesh, shp, vertexBuffer, model);
mesh.MaterialIndex = shp.MaterialIndex; mesh.MaterialIndex = shp.MaterialIndex;
@ -449,9 +446,6 @@ namespace FirstPlugin
curve.CurveType = AnimCurveType.StepBool; curve.CurveType = AnimCurveType.StepBool;
curve.Keys = new float[keyGroup.Keys.Count, 1]; curve.Keys = new float[keyGroup.Keys.Count, 1];
} }
return curve; return curve;
} }
@ -472,7 +466,6 @@ namespace FirstPlugin
{ {
BfresBone STBone = new BfresBone(RenderableSkeleton); BfresBone STBone = new BfresBone(RenderableSkeleton);
SetBone(STBone, bone); SetBone(STBone, bone);
STBone.BFRESRender = RenderableSkeleton.node.BFRESRender; //to update viewport on bone edits
RenderableSkeleton.bones.Add(STBone); RenderableSkeleton.bones.Add(STBone);
} }
RenderableSkeleton.update(); RenderableSkeleton.update();

View File

@ -30,13 +30,11 @@ namespace FirstPlugin
model.Nodes.Add(model.Skeleton.node); model.Nodes.Add(model.Skeleton.node);
model.Skeleton.reset(); model.Skeleton.reset();
model.Skeleton.update(); model.Skeleton.update();
model.BFRESRender = renderer;
model.Skeleton.node.BFRESRender = renderer; model.Skeleton.node.BFRESRender = renderer;
model.ModelU = mdl; model.ModelU = mdl;
foreach (Material mat in mdl.Materials.Values) foreach (Material mat in mdl.Materials.Values)
{ {
FMAT FMAT = new FMAT(); FMAT FMAT = new FMAT();
FMAT.BFRESRender = renderer;
FMAT.Text = mat.Name; FMAT.Text = mat.Name;
FMAT.ReadMaterial(mat); FMAT.ReadMaterial(mat);
model.Nodes[1].Nodes.Add(FMAT); model.Nodes[1].Nodes.Add(FMAT);
@ -47,7 +45,6 @@ namespace FirstPlugin
VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex]; VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex];
Material material = mdl.Materials[shp.MaterialIndex]; Material material = mdl.Materials[shp.MaterialIndex];
FSHP mesh = new FSHP(); FSHP mesh = new FSHP();
mesh.BFRESRender = renderer;
mesh.ModelIndex = CurMdl; mesh.ModelIndex = CurMdl;
ReadShapesVertices(mesh, shp, vertexBuffer, model); ReadShapesVertices(mesh, shp, vertexBuffer, model);
mesh.MaterialIndex = shp.MaterialIndex; mesh.MaterialIndex = shp.MaterialIndex;
@ -619,7 +616,7 @@ namespace FirstPlugin
TextureRef texref = new TextureRef(); TextureRef texref = new TextureRef();
texref.Name = textu.Name; texref.Name = textu.Name;
Texture texMapped = new Texture(); Texture texMapped = new Texture();
m.BFRESRender.resFileU.Textures.TryGetValue(textu.Name, out texMapped); m.GetResFileU().Textures.TryGetValue(textu.Name, out texMapped);
texref.Texture = texMapped; texref.Texture = texMapped;
mat.TextureRefs.Add(texref); mat.TextureRefs.Add(texref);
} }

View File

@ -170,6 +170,7 @@ namespace FirstPlugin
format = (int)tex.Format; format = (int)tex.Format;
int swizzle = (int)tex.Swizzle; int swizzle = (int)tex.Swizzle;
int pitch = (int)tex.Pitch; int pitch = (int)tex.Pitch;
renderedTex.data = GTX.swizzleBC(tex.Data, renderedTex.width, renderedTex.height, format, (int)tex.TileMode, pitch, swizzle); renderedTex.data = GTX.swizzleBC(tex.Data, renderedTex.width, renderedTex.height, format, (int)tex.TileMode, pitch, swizzle);
} }
@ -393,6 +394,7 @@ namespace FirstPlugin
} }
set set
{ {
mipmaps.Clear();
List<byte[]> mips = new List<byte[]>(); List<byte[]> mips = new List<byte[]>();
mips.Add(value); mips.Add(value);
mipmaps.Add(mips); mipmaps.Add(mips);

View File

@ -28,9 +28,6 @@ namespace FirstPlugin
int vbo_position; int vbo_position;
int ibo_elements; int ibo_elements;
public ResFile resFile = null;
public ResU.ResFile resFileU = null;
public Shader shader = null; public Shader shader = null;
public List<FMDL> models = new List<FMDL>(); public List<FMDL> models = new List<FMDL>();
@ -51,18 +48,16 @@ namespace FirstPlugin
GL.GenBuffers(1, out vbo_position); GL.GenBuffers(1, out vbo_position);
GL.GenBuffers(1, out ibo_elements); GL.GenBuffers(1, out ibo_elements);
} }
public void LoadFile(ResU.ResFile r) public void LoadFile(ResU.ResFile resFileU)
{ {
resFileU = r;
ResFileNode.Load(resFileU); ResFileNode.Load(resFileU);
BfresWiiU.Read(this, resFileU, ResFileNode); BfresWiiU.Read(this, resFileU, ResFileNode);
UpdateVertexData(); UpdateVertexData();
UpdateTextureMaps(); UpdateTextureMaps();
} }
public void LoadFile(ResFile r) public void LoadFile(ResFile resFile)
{ {
resFile = r;
ResFileNode.Load(resFile); ResFileNode.Load(resFile);
BfresSwitch.Read(this, resFile, ResFileNode); BfresSwitch.Read(this, resFile, ResFileNode);

View File

@ -19,8 +19,6 @@ namespace FirstPlugin
{ {
public FMAT material; public FMAT material;
public BFRESRender bfresRender;
public ImageList textureImageList; public ImageList textureImageList;
public string SelectedMatParam = ""; public string SelectedMatParam = "";
public ImageList il = new ImageList(); public ImageList il = new ImageList();
@ -46,9 +44,8 @@ namespace FirstPlugin
{ {
} }
public void LoadMaterial(FMAT mat, BFRESRender bfres) public void LoadMaterial(FMAT mat)
{ {
bfresRender = bfres;
material = mat; material = mat;
textBoxMaterialName.Text = material.Text; textBoxMaterialName.Text = material.Text;
@ -320,7 +317,7 @@ namespace FirstPlugin
{ {
material.textures[index].Name = tex.GetSelectedTexture(); material.textures[index].Name = tex.GetSelectedTexture();
InitializeTextureListView(material); InitializeTextureListView(material);
bfresRender.UpdateSingleMaterialTextureMaps(material); material.UpdateTextureMaps();
} }
} }

View File

@ -324,7 +324,7 @@ namespace FirstPlugin
if (LODMeshCB.SelectedIndex != -1) if (LODMeshCB.SelectedIndex != -1)
{ {
activeShape.DisplayLODIndex = LODMeshCB.SelectedIndex; activeShape.DisplayLODIndex = LODMeshCB.SelectedIndex;
activeShape.BFRESRender.UpdateVertexData(); activeShape.UpdateVertexData();
Viewport.Instance.UpdateViewport(); Viewport.Instance.UpdateViewport();
} }
} }

View File

@ -75,7 +75,7 @@ namespace FirstPlugin
FMATEditor editor = new FMATEditor(); FMATEditor editor = new FMATEditor();
editor.Text = mat.Text; editor.Text = mat.Text;
editor.Dock = DockStyle.Fill; editor.Dock = DockStyle.Fill;
editor.LoadMaterial(mat, mat.BFRESRender); editor.LoadMaterial(mat);
LibraryGUI.Instance.LoadDockContent(editor, PluginRuntime.FSHPDockState); LibraryGUI.Instance.LoadDockContent(editor, PluginRuntime.FSHPDockState);
} }

View File

@ -18,8 +18,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Updater", "Updater\Updater.
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "Switch_Toolbox\Lib\DirectXTex\DirectXTex.vcxproj", "{755AB64B-16B4-4C90-AA3B-BFF448E5A21E}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "Switch_Toolbox\Lib\DirectXTex\DirectXTex.vcxproj", "{755AB64B-16B4-4C90-AA3B-BFF448E5A21E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectXTexNet", "DirectXTexNet-master\DirectXTexNet\DirectXTexNet.csproj", "{98495BF2-DED3-4E08-B965-C12D471BC86F}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -75,14 +73,6 @@ Global
{755AB64B-16B4-4C90-AA3B-BFF448E5A21E}.Release|Any CPU.Build.0 = Release|Win32 {755AB64B-16B4-4C90-AA3B-BFF448E5A21E}.Release|Any CPU.Build.0 = Release|Win32
{755AB64B-16B4-4C90-AA3B-BFF448E5A21E}.Release|x64.ActiveCfg = Release|x64 {755AB64B-16B4-4C90-AA3B-BFF448E5A21E}.Release|x64.ActiveCfg = Release|x64
{755AB64B-16B4-4C90-AA3B-BFF448E5A21E}.Release|x64.Build.0 = Release|x64 {755AB64B-16B4-4C90-AA3B-BFF448E5A21E}.Release|x64.Build.0 = Release|x64
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Debug|x64.ActiveCfg = Debug|Any CPU
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Debug|x64.Build.0 = Debug|Any CPU
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Release|Any CPU.Build.0 = Release|Any CPU
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Release|x64.ActiveCfg = Release|Any CPU
{98495BF2-DED3-4E08-B965-C12D471BC86F}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -265,9 +265,9 @@ namespace Switch_Toolbox
f.Dispose(); f.Dispose();
f.Close(); f.Close();
//Check magic first regardless of extension
foreach (IFileFormat format in SupportedFormats) foreach (IFileFormat format in SupportedFormats)
{ {
if (format.Magic == Magic || format.Magic == Magic2 || format.Magic.Reverse() == Magic2) if (format.Magic == Magic || format.Magic == Magic2 || format.Magic.Reverse() == Magic2)
{ {
format.CompressionType = CompType; format.CompressionType = CompType;
@ -290,7 +290,9 @@ namespace Switch_Toolbox
if (format.UseEditMenu) if (format.UseEditMenu)
editToolStripMenuItem.Enabled = true; editToolStripMenuItem.Enabled = true;
} }
else }
//If magic fails, then check extensions
foreach (IFileFormat format in SupportedFormats)
{ {
foreach (string ext in format.Extension) foreach (string ext in format.Extension)
{ {
@ -319,14 +321,15 @@ namespace Switch_Toolbox
} }
} }
} }
}
private void DisposeControls() private void DisposeControls()
{ {
} }
private void RecentFile_click(object sender, EventArgs e) private void RecentFile_click(object sender, EventArgs e)
{ {
Cursor.Current = Cursors.WaitCursor;
OpenFile(sender.ToString()); OpenFile(sender.ToString());
Cursor.Current = Cursors.Default;
} }
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{ {
@ -362,8 +365,12 @@ namespace Switch_Toolbox
if (ofd.ShowDialog() == DialogResult.OK) if (ofd.ShowDialog() == DialogResult.OK)
{ {
Cursor.Current = Cursors.WaitCursor;
foreach (string file in ofd.FileNames) foreach (string file in ofd.FileNames)
OpenFile(file); OpenFile(file);
Cursor.Current = Cursors.Default;
} }
} }
@ -375,11 +382,15 @@ namespace Switch_Toolbox
private void dockPanel1_DragDrop(object sender, DragEventArgs e) private void dockPanel1_DragDrop(object sender, DragEventArgs e)
{ {
Cursor.Current = Cursors.WaitCursor;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string filename in files) foreach (string filename in files)
{ {
OpenFile(filename); OpenFile(filename);
} }
Cursor.Current = Cursors.Default;
} }
private void dockPanel1_DragEnter(object sender, DragEventArgs e) private void dockPanel1_DragEnter(object sender, DragEventArgs e)