static void ExportTextures(BFRES model, string ModelsFolder) { if (model.textures.Keys.Count > 0) { if (!Directory.Exists(String.Format("{0}", ModelsFolder + "/" + textureFolder))) { Directory.CreateDirectory(String.Format("{0}", ModelsFolder + "/" + textureFolder)); } foreach (string k in model.textures.Keys) { foreach (var tex in model.textures[k].Textures.Where( x => IsMaterialNameValid(x.Name))) { if (!File.Exists(String.Format("{0}", ModelsFolder + "/" + textureFolder + "/" + tex.Name + "." + texFmt))) { ExportTexture(tex, String.Format("{0}", ModelsFolder + "/" + textureFolder + "/" + tex.Name + "." + texFmt)); } else { Console.WriteLine("Skipped texture " + tex.Name); } } } } }
static void ExportTextures(BFRES model, string ModelsFolder) { if (model.textures.Keys.Count > 0) { if (!Directory.Exists($"{ModelsFolder}/{textureFolder}")) { Directory.CreateDirectory($"{ModelsFolder}/{textureFolder}"); } foreach (string k in model.textures.Keys) { foreach (var tex in model.textures[k].Textures.Where( x => IsMaterialNameValid(x.Name))) { if (!File.Exists($"{ModelsFolder}/{textureFolder}/{tex.Name}.{texFmt}")) { ExportTexture(tex, $"{ModelsFolder}/{textureFolder}/{tex.Name}.{texFmt}"); } else { Console.WriteLine("Skipped texture " + tex.Name); } } } } }
public void AddRenderableBfres(string FilePath) { if (!System.IO.File.Exists(FilePath)) { return; } BFRES bfres = (BFRES)Switch_Toolbox.Library.IO.STFileLoader.OpenFileFormat(FilePath); if (bfres != null) { BfresObjects.Add(bfres); } }
public static bool GetTextures(byte[] bfres, string Folder) { if (bfres == null) { return(false); } BFRES s = new BFRES(); s.Read(bfres); ExportTextures(s, Folder); bool res = s.models.Count != 0; s = null; GC.Collect(); return(res); }
/// <summary> /// Exports all models from the target bfres to the selected folder. /// Returns array with the converted file names, it's NULL if no models were converted /// </summary> /// <param name="bfres">Source brfs</param> /// <param name="outDir">Target directory</param> /// <returns></returns> public static string[] Convert(byte[] bfres, string outDir) { if (bfres == null) { return(null); } BFRES s = new BFRES(); s.Read(bfres); Export(outDir, s); var res = s.models.Count == 0 ? null : s.models.Select(x => x.name).ToArray(); s = null; GC.Collect(); return(res); }
public static bool Convert(byte[] bfres, string outPath) { if (bfres == null) { return(false); } BFRES s = new BFRES(); s.Read(bfres); Export(outPath, s); bool res = s.models.Count != 0; s = null; GC.Collect(); return(res); }
public static bool GetTextures(byte[] bfres, string Folder) { if (bfres == null) { return(false); } BFRES s = new BFRES(); s.Read(bfres); ExportTextures(s, Folder); GC.Collect(); if (s.textures.Count == 0) { return(false); } return(true); }
public static bool Convert(byte[] bfres, string outPath) { if (bfres == null) { return(false); } BFRES s = new BFRES(); s.Read(bfres); Export(outPath, s); GC.Collect(); if (s.models.Count == 0) { return(false); } return(true); }
private void testBFRESToolStripMenuItem_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { ofd.Filter = "BFRES files (*.bfres)|*.bfres|All files (*.*)|*.*"; if (ofd.ShowDialog(this) != DialogResult.OK) { return; } using (var stream = ofd.OpenFile()) { BFRES file = new BFRES(stream); file.ToString(); } } }
public void LoadViewport(BFRES bfres, bool hasShapes, DrawableContainer activeDrawable, List <ToolStripMenuItem> customContextMenus = null) { ActiveBfres = bfres; HasShapes = hasShapes; ActiveDrawable = activeDrawable; if (!Runtime.UseOpenGL || !DisplayViewport) { return; } ReloadDrawableList(); if (customContextMenus != null) { foreach (var menu in customContextMenus) { viewport.LoadCustomMenuItem(menu); } } OnLoadedTab(); }
private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); List <IFileFormat> formats = new List <IFileFormat>(); formats.Add(new BFRES()); ofd.Filter = Utils.GetAllFilters(formats); if (ofd.ShowDialog() == DialogResult.OK) { var format = STFileLoader.OpenFileFormat(ofd.FileName); if (format != null) { if (format is SARC) { foreach (SARC.SarcEntry fileNode in ((SARC)format).Nodes) { if (fileNode.ImageKey == "bfres") { var sarcFile = STFileLoader.OpenFileFormat(fileNode.FullName, fileNode.Data, false, true); bfres = (BFRES)sarcFile; } } } else if (format is BFRES) { bfres = (BFRES)format; } else { throw new Exception("Failed to load bfres file. "); } } } }
private void PerformOpen(string where) { treeView1.Nodes.Clear(); isNodeSelected = false; EndianBinaryReader reader = new EndianBinaryReader(File.Open(where, FileMode.Open)); BEA bea = new BEA(ref reader); string fileName = Path.GetFileName(where); string assetNumber = fileName.Split('_', '.')[1]; byte[] bfresArray = bea.GetAssetDataByKey(String.Format("mainmode/bds001_{0}/model/bds001_{0}_hook_mass.fmdb", assetNumber)); if (bfresArray == null) { MessageBox.Show("The archive selected does not contain hooks for spaces."); return; } EndianBinaryReader bfresReader = new EndianBinaryReader(bfresArray); mBfres = new BFRES(ref bfresReader); byte[] csvArray = bea.GetAssetDataByKey(String.Format("mainmode/bds001_{0}/csv/bds001_{0}_map.csv", assetNumber)); if (csvArray == null) { MessageBox.Show("The archive selected does not contain the CSV file for space attributes."); return; } StreamReader txtReader = new StreamReader(new MemoryStream(csvArray), Encoding.GetEncoding(932)); mBoard = new Board(ref txtReader); mNodes = new Dictionary <string, SpaceNode>(); foreach (FSKL.Bone bone in mBfres.mSkeleton.mBones) { SpaceNode node = GetSpaceFromKey(bone.mName); mNodes.Add(bone.mName, GetSpaceFromKey(bone.mName)); if (node != null) { node.SetPosition(bone.mTranslation); string nodeName; try { nodeName = Helper.mSimpleNodeNames[node.mSpaceType]; } catch { nodeName = node.mSpaceType; } TreeNode tnode = new TreeNode(nodeName) { Tag = node }; treeView1.Nodes.Add(tnode); } } drawFlag = true; statusStrip.Text = "File successfully loaded!"; panel1.Invalidate(); }
public void AddRenderableBfres(string FilePath) { BFRES bfres = (BFRES)Switch_Toolbox.Library.IO.STFileLoader.OpenFileFormat(FilePath); BfresObjects.Add(bfres); }
internal static void Export(string FileName, BFRES model) { bool UseEmptyMat = false; List <string> ExportMats = new List <string>(); if (model.models.Count > 0) { using (System.IO.StreamWriter f = new System.IO.StreamWriter(FileName)) { f.WriteLine($"mtllib {Path.GetFileNameWithoutExtension(FileName)}.mtl"); int vertexOffest = 1; foreach (var mesh in model.models[0].poly) { bool NoTexture = mesh.vertices[0].tx.Count == 0; foreach (var v in mesh.vertices) { f.WriteLine($"v {v.pos.X} {v.pos.Y} {v.pos.Z}"); //{v.col.X} {v.col.Y} {v.col.Z} are vertex colors (unsupported for OBJ) if (!NoTexture) { f.WriteLine($"vt {v.tx[0].X } {1 - v.tx[0].Y}"); } else { f.WriteLine($"vt 0 0"); //Or else offsets won't match } f.WriteLine($"vn {v.nrm.X} {v.nrm.Y} {v.nrm.Z}"); } if (mesh.texNames.Count == 0) { UseEmptyMat = true; NoTexture = true; f.WriteLine($"usemtl OdysseyEditor_EmptyMat"); } else { foreach (string m in mesh.texNames) { if (!ExportMats.Contains(m)) { ExportMats.Add(m); } } f.WriteLine($"usemtl {mesh.texNames[0]}"); } for (int i = 0; i < mesh.faces.Count; i++) { var verts = mesh.faces[i]; //Debug.Assert(verts[0] == verts[1] && verts[2] == verts[1]); int val = verts[0] + vertexOffest; int val1 = verts[1] + vertexOffest; int val2 = verts[2] + vertexOffest; if (!NoTexture) { f.WriteLine($"f {val}/{val}/{val} {val1}/{val1}/{val1} {val2}/{val2}/{val2}"); } else { f.WriteLine($"f {val}//{val} {val1}//{val1} {val2}//{val2}"); } } vertexOffest += mesh.vertices.Count; } } using (System.IO.StreamWriter f = new System.IO.StreamWriter(FileName.Substring(0, FileName.Length - 3) + "mtl")) { if (UseEmptyMat) { f.WriteLine($"newmtl OdysseyEditor_EmptyMat"); f.WriteLine($"Ka 0.000000 0.000000 0.000000"); f.WriteLine($"Kd 0.800000 0.800000 0.800000"); f.WriteLine($"Ks 0.0 0.0 0.0 \n"); } foreach (string MatName in ExportMats) { if (!IsMaterialNameValid(MatName)) { continue; //If a material texture is missing the mesh will not show, skip non "alb" materials } f.WriteLine($"newmtl {MatName}"); f.WriteLine($"Ka 0.000000 0.000000 0.000000"); f.WriteLine($"Kd 1.000000 1.000000 1.000000"); f.WriteLine($"Ks 0.0 0.0 0.0 "); f.WriteLine($"map_Kd {textureFolder}/{MatName}.{texFmt}\n"); } } } ExportTextures(model, Path.GetDirectoryName(FileName)); }