private static void ExecOptions(AbstractTriangleMesh mesh) { while (true) { if (mesh.GetType() == typeof(IFLTriangleMesh)) { Console.WriteLine("-------------------"); Console.WriteLine("Press (C) to convert mesh to laced ring or (E) to exit program"); String line = Console.ReadLine(); if (line.ToLower() == "c") { Console.WriteLine("-------------------"); Console.WriteLine("Start converting mesh"); IConverter <LRTriangleMesh> converter = Converter.GetSpecificConverter <IFLTriangleMesh, LRTriangleMesh>((IFLTriangleMesh)mesh); mesh = converter.Convert(); Console.WriteLine("-------------------"); Console.WriteLine("Mesh successfully converted "); } else if (line.ToLower() == "e") { Environment.Exit(0); } else { Console.WriteLine("-------------------"); Console.WriteLine("Command not recognized"); } } else if (mesh.GetType() == typeof(LRTriangleMesh)) { Console.WriteLine("-------------------"); Console.WriteLine("Press (S) to save mesh or (E) to exit program"); String line = Console.ReadLine(); if (line.ToLower() == "s") { Console.WriteLine("-------------------"); Console.WriteLine("Path were mesh should be saved:"); String path = Console.ReadLine(); Console.WriteLine("Filename:"); String fileName = Console.ReadLine(); Console.WriteLine("-------------------"); Console.WriteLine("Start writting mesh"); MeshWriter.WriteMesh(Path.Combine(path + fileName), mesh); Console.WriteLine("-------------------"); Console.WriteLine("Mesh successfully written"); } else if (line.ToLower() == "e") { Environment.Exit(0); } else { Console.WriteLine("-------------------"); Console.WriteLine("Command not recognized"); } } } }
private void ExportToolStripMenuItem_Click(object sender, EventArgs e) { //ToolTipText is the full filename var fileName = ((ToolStripMenuItem)sender).ToolTipText; var tag = ((ToolStripMenuItem)sender).Tag as ExportData; var resource = tag.Resource; Console.WriteLine($"Export requested for {fileName}"); string[] extensions = null; switch (resource.ResourceType) { case ResourceType.Sound: //WAV or MP3 extensions = new[] { ((Sound)resource.DataBlock).SoundType.ToString().ToLower() }; break; case ResourceType.Texture: extensions = new[] { "png" }; break; case ResourceType.PanoramaLayout: extensions = new[] { "xml", "vxml" }; break; case ResourceType.PanoramaScript: extensions = new[] { "js", "vjs" }; break; case ResourceType.PanoramaStyle: extensions = new[] { "css", "vcss" }; break; case ResourceType.Mesh: extensions = new[] { "obj" }; break; } //Did we find a format we like? if (extensions != null) { var dialog = new SaveFileDialog { FileName = Path.GetFileName(Path.ChangeExtension(fileName, extensions[0])), InitialDirectory = Settings.Config.SaveDirectory, DefaultExt = extensions[0], }; var filter = string.Empty; foreach (var extension in extensions) { filter += $"{extension} files (*.{extension})|*.{extension}|"; } //Remove the last | dialog.Filter = filter.Substring(0, filter.Length - 1); var result = dialog.ShowDialog(); if (result == DialogResult.OK) { Settings.Config.SaveDirectory = Path.GetDirectoryName(dialog.FileName); Settings.Save(); using (var stream = dialog.OpenFile()) { // TODO: move this to FileExtract/VRF too if (resource.ResourceType == ResourceType.Mesh) { using (var objStream = new StreamWriter(stream)) using (var mtlStream = new StreamWriter(Path.ChangeExtension(dialog.FileName, "mtl"))) { MeshWriter.WriteObject(objStream, mtlStream, Path.GetFileNameWithoutExtension(dialog.FileName), resource); } foreach (var texture in tag.VrfGuiContext.MaterialLoader.LoadedTextures) { Console.WriteLine($"Exporting texture for mesh: {texture}"); var textureResource = tag.VrfGuiContext.LoadFileByAnyMeansNecessary(texture + "_c"); var textureImage = SKImage.FromBitmap(((Texture)textureResource.DataBlock).GenerateBitmap()); using (var texStream = new FileStream(Path.Combine(Path.GetDirectoryName(dialog.FileName), Path.GetFileNameWithoutExtension(texture) + ".png"), FileMode.Create, FileAccess.Write)) using (var data = textureImage.Encode(SKEncodedImageFormat.Png, 100)) { data.SaveTo(texStream); } } } else { var data = FileExtract.Extract(resource).ToArray(); stream.Write(data, 0, data.Length); } } } } Console.WriteLine($"Export requested for {fileName} Complete"); }