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; }
// // [TODO] // static void Main(string[] args) { CommandArgumentSet arguments = new CommandArgumentSet(); arguments.Register("-output", ""); if (arguments.Parse(args) == false) { return; } if (arguments.Filenames.Count != 1) { print_usage(); return; } string sInputFile = arguments.Filenames[0]; string sFilenameRoot = Path.GetFileNameWithoutExtension(sInputFile); if (!File.Exists(sInputFile)) { System.Console.WriteLine("cannot find file " + sInputFile); return; } DMesh3Builder builder = new DMesh3Builder(); StandardMeshReader reader = new StandardMeshReader() { MeshBuilder = builder }; ReadOptions read_options = ReadOptions.Defaults; read_options.ReadMaterials = true; IOReadResult readOK = reader.Read(sInputFile, read_options); if (readOK.code != IOCode.Ok) { System.Console.WriteLine("Error reading " + sInputFile); System.Console.WriteLine(readOK.message); return; } if (builder.Meshes.Count == 0) { System.Console.WriteLine("did not find any valid meshes in " + sInputFile); return; } // [TODO] out if count == 0 string sOutRoot = arguments.Strings["-output"]; if (sOutRoot.Length > 0) { bool bOutIsFolder = Directory.Exists(sOutRoot); if (!bOutIsFolder) { System.Console.WriteLine("-output folder {0} does not exist", sOutRoot); return; } } Dictionary <int, List <int> > MeshesByMaterial = new Dictionary <int, List <int> >(); MeshesByMaterial[-1] = new List <int>(); for (int i = 0; i < builder.Materials.Count; ++i) { MeshesByMaterial[i] = new List <int>(); } int N = builder.Meshes.Count; for (int i = 0; i < N; ++i) { int mati = builder.MaterialAssignment[i]; if (mati >= builder.Materials.Count) { mati = -1; } MeshesByMaterial[mati].Add(i); } int file_i = 0; foreach (int mat_i in MeshesByMaterial.Keys) { List <int> mesh_idxs = MeshesByMaterial[mat_i]; if (mesh_idxs.Count == 0) { continue; } WriteMesh[] write_meshes = new WriteMesh[mesh_idxs.Count]; for (int i = 0; i < mesh_idxs.Count; ++i) { write_meshes[i] = new WriteMesh(builder.Meshes[mesh_idxs[i]]); } string suffix = string.Format("_material{0}", file_i++); string sOutPath = Path.Combine(sOutRoot, sFilenameRoot + suffix + ".obj"); StandardMeshWriter writer = new StandardMeshWriter(); WriteOptions write_options = WriteOptions.Defaults; if (mat_i != -1) { write_options.bWriteMaterials = true; write_options.bPerVertexUVs = true; write_options.MaterialFilePath = Path.Combine(sOutRoot, sFilenameRoot + suffix + ".mtl"); GenericMaterial mat = builder.Materials[mat_i]; List <GenericMaterial> matList = new List <GenericMaterial>() { mat }; ConstantIndexMap idxmap = new ConstantIndexMap(0); for (int i = 0; i < write_meshes.Length; ++i) { write_meshes[i].Materials = matList; write_meshes[i].TriToMaterialMap = idxmap; } } IOWriteResult writeOK = writer.Write(sOutPath, new List <WriteMesh>(write_meshes), write_options); if (writeOK.code != IOCode.Ok) { System.Console.WriteLine("Error writing " + sOutPath); System.Console.WriteLine(writeOK.message); } } // ok done! //System.Console.ReadKey(); }
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); } }
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; }