static void Main(string[] args) { // [RMS] if true, we try to read back the file we wrote to make sure that works bool bTestRead = true; CommandArgumentSet arguments = new CommandArgumentSet(); arguments.Register("-string", ""); arguments.Register("-font", "Consolas"); arguments.Register("-emSize", 64); arguments.Register("-style", "regular"); if (arguments.Parse(args) == false) { return; } if (arguments.Filenames.Count != 1) { print_usage(); return; } string outputFilename = arguments.Filenames[0]; string fontName = "Consolas"; if (arguments.Saw("-font")) { fontName = arguments.Strings["-font"]; } int emSize = 64; if (arguments.Saw("-emSize")) { emSize = arguments.Integers["-emSize"]; } FontStyle style = FontStyle.Regular; if (arguments.Saw("-style")) { string s = arguments.Strings["-style"]; if (s.Equals("bold", StringComparison.OrdinalIgnoreCase)) { style = FontStyle.Bold; } else if (s.Equals("italic", StringComparison.OrdinalIgnoreCase)) { style = FontStyle.Italic; } else if (s.Equals("regular", StringComparison.OrdinalIgnoreCase) == false) { System.Console.WriteLine("Unknown font style '{0}'", s); return; } } // [RMS] these are the characters that will be in the output, unless... string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,;:-+=!?()[]<>{}|~@#$%^&*_/\\\"'`©™"; string[] strings = new string[characters.Length]; for (int k = 0; k < characters.Length; ++k) { strings[k] = characters.Substring(k, 1); } // override with a fixed string if (arguments.Saw("-string")) { strings = new string[1]; strings[0] = arguments.Strings["-string"]; } // generate polygons for each character and add to font PolygonFont2d Font = new PolygonFont2d(); try { for (int k = 0; k < strings.Length; ++k) { string s = strings[k]; List <GeneralPolygon2d> loops = GetPolygons(s, fontName, style, emSize); Font.AddCharacter(s, loops.ToArray()); } } catch (Exception e) { System.Console.WriteLine("Exception generating font: " + e.Message); } // write font to output file try { using (FileStream file_stream = File.Open(outputFilename, FileMode.Create)) { BinaryWriter w = new BinaryWriter(file_stream); PolygonFont2d.Store(Font, w); } } catch (Exception e) { System.Console.WriteLine("Exception serializing font: " + e.Message); } // read font back in to test if (bTestRead) { try { using (FileStream file_stream = File.Open(outputFilename, FileMode.Open)) { BinaryReader binReader = new BinaryReader(file_stream); PolygonFont2d newfont = new PolygonFont2d(); PolygonFont2d.Restore(newfont, binReader); } } catch (Exception e) { System.Console.WriteLine("Error verifying font read: " + e.Message); } } // print status if (strings.Length == 1) { System.Console.WriteLine("Wrote string \"{0}\" to {1}", strings[0], outputFilename); } else { System.Console.WriteLine("Wrote {0} font characters to {1}", Font.Characters.Count, outputFilename); } }
public static void Main(string[] args) { CommandArgumentSet arguments = new CommandArgumentSet(); //arguments.Register("-tcount", int.MaxValue); //arguments.Register("-percent", 50.0f); //arguments.Register("-v", false); arguments.Register("-output", ""); if (arguments.Parse(args) == false) { return; } if (arguments.Filenames.Count != 1) { print_usage(); return; } string inputFilename = arguments.Filenames[0]; if (!File.Exists(inputFilename)) { System.Console.WriteLine("File {0} does not exist", inputFilename); return; } string outputFilename = Path.GetFileNameWithoutExtension(inputFilename); string format = Path.GetExtension(inputFilename); outputFilename = outputFilename + ".repaired" + format; if (arguments.Saw("-output")) { outputFilename = arguments.Strings["-output"]; } //int triCount = int.MaxValue; //if (arguments.Saw("-tcount")) // triCount = arguments.Integers["-tcount"]; //float percent = 50.0f; //if (arguments.Saw("-percent")) // percent = arguments.Floats["-percent"]; bool verbose = true; //if (arguments.Saw("-v")) // verbose = arguments.Flags["-v"]; List <DMesh3> meshes; try { DMesh3Builder builder = new DMesh3Builder(); IOReadResult result = StandardMeshReader.ReadFile(inputFilename, ReadOptions.Defaults, builder); if (result.code != IOCode.Ok) { System.Console.WriteLine("Error reading {0} : {1}", inputFilename, result.message); return; } meshes = builder.Meshes; } catch (Exception e) { System.Console.WriteLine("Exception reading {0} : {1}", inputFilename, e.Message); return; } if (meshes.Count == 0) { System.Console.WriteLine("file did not contain any valid meshes"); return; } DMesh3 mesh = meshes[0]; for (int k = 1; k < meshes.Count; ++k) { MeshEditor.Append(mesh, meshes[k]); } if (mesh.TriangleCount == 0) { System.Console.WriteLine("mesh does not contain any triangles"); return; } if (verbose) { System.Console.WriteLine("initial mesh contains {0} triangles", mesh.TriangleCount); } if (verbose) { System.Console.WriteLine("Repairing...", mesh.TriangleCount); } MeshAutoRepair repair = new MeshAutoRepair(mesh); repair.RemoveMode = MeshAutoRepair.RemoveModes.None; bool bOK = repair.Apply(); if (verbose) { if (bOK == false) { System.Console.WriteLine("repair failed!"); } else { System.Console.WriteLine("done! repaired mesh contains {0} triangles", mesh.TriangleCount); } } try { IOWriteResult wresult = StandardMeshWriter.WriteMesh(outputFilename, mesh, WriteOptions.Defaults); if (wresult.code != IOCode.Ok) { System.Console.WriteLine("Error writing {0} : {1}", inputFilename, wresult.message); return; } } catch (Exception e) { System.Console.WriteLine("Exception reading {0} : {1}", inputFilename, e.Message); return; } return; }
static void Main(string[] args) { CommandArgumentSet arguments = new CommandArgumentSet(); arguments.Register("-tcount", int.MaxValue); arguments.Register("-percent", 50.0f); arguments.Register("-v", false); arguments.Register("-output", ""); if (arguments.Parse(args) == false) { return; } if (arguments.Filenames.Count != 1) { print_usage(); return; } string inputFilename = arguments.Filenames[0]; if (!File.Exists(inputFilename)) { System.Console.WriteLine("File {0} does not exist", inputFilename); return; } string outputFilename = Path.GetFileNameWithoutExtension(inputFilename); string format = Path.GetExtension(inputFilename); outputFilename = outputFilename + ".reduced" + format; if (arguments.Saw("-output")) { outputFilename = arguments.Strings["-output"]; } int triCount = int.MaxValue; if (arguments.Saw("-tcount")) { triCount = arguments.Integers["-tcount"]; } float percent = 50.0f; if (arguments.Saw("-percent")) { percent = arguments.Floats["-percent"]; } bool verbose = false; if (arguments.Saw("-v")) { verbose = arguments.Flags["-v"]; } List <DMesh3> meshes; try { DMesh3Builder builder = new DMesh3Builder(); IOReadResult result = StandardMeshReader.ReadFile(inputFilename, ReadOptions.Defaults, builder); if (result.code != IOCode.Ok) { System.Console.WriteLine("Error reading {0} : {1}", inputFilename, result.message); return; } meshes = builder.Meshes; } catch (Exception e) { System.Console.WriteLine("Exception reading {0} : {1}", inputFilename, e.Message); return; } if (meshes.Count == 0) { System.Console.WriteLine("file did not contain any valid meshes"); return; } DMesh3 mesh = meshes[0]; for (int k = 1; k < meshes.Count; ++k) { MeshEditor.Append(mesh, meshes[k]); } if (mesh.TriangleCount == 0) { System.Console.WriteLine("mesh does not contain any triangles"); return; } if (verbose) { System.Console.WriteLine("initial mesh contains {0} triangles", mesh.TriangleCount); } Reducer r = new Reducer(mesh); if (triCount < int.MaxValue) { if (verbose) { System.Console.Write("reducing to {0} triangles...", triCount); } r.ReduceToTriangleCount(triCount); } else { int nT = (int)((float)mesh.TriangleCount * percent / 100.0f); nT = MathUtil.Clamp(nT, 1, mesh.TriangleCount); if (verbose) { System.Console.Write("reducing to {0} triangles...", nT); } r.ReduceToTriangleCount(nT); } if (verbose) { System.Console.WriteLine("done!"); } try { IOWriteResult wresult = StandardMeshWriter.WriteMesh(outputFilename, mesh, WriteOptions.Defaults); if (wresult.code != IOCode.Ok) { System.Console.WriteLine("Error writing {0} : {1}", inputFilename, wresult.message); return; } } catch (Exception e) { System.Console.WriteLine("Exception reading {0} : {1}", inputFilename, e.Message); return; } return; }