private void generateButton_Click(object sender, EventArgs e) { NavMeshConfigurationFile setting = propertyGrid1.SelectedObject as NavMeshConfigurationFile; if (setting == null) { return; } List <ObjModel> models = new List <ObjModel>(); if (setting.InputMeshes.Count == 0) { MessageBox.Show("No Obj files included"); return; } foreach (var mesh in setting.InputMeshes) { //mesh.vector = new Vector3(mesh.Position[0], mesh.Position[1], mesh.Position[2]); if (File.Exists(mesh.Path)) { ObjModel obj = new ObjModel(mesh.Path); float scale = mesh.Scale; //TODO SCALE THE OBJ FILE models.Add(obj); } else { MessageBox.Show(mesh.Path + "\nObj file not exists."); } } }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { if (changed == false) { Application.Exit(); } else { DialogResult result = MessageBox.Show("Save before Exit?", "SharpNav GUI", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { if (cwd == null) { saveAsToolStripMenuItem_Click(sender, e); } else { NavMeshConfigurationFile setting = propertyGrid1.SelectedObject as NavMeshConfigurationFile; saveprocess(setting, cwd); } Application.Exit(); } else if (result == DialogResult.No) { Application.Exit(); } } }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { NavMeshConfigurationFile file = new NavMeshConfigurationFile(); file.GenerationSettings = NavMeshGenerationSettings.Default; file.ExportPath = "default.snb"; propertyGrid1.SelectedObject = file; changed = true; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openSettingsFileDialog.ShowDialog() == DialogResult.OK) { var input = new StreamReader(File.OpenRead(openSettingsFileDialog.FileName)); var file = new NavMeshConfigurationFile(input); propertyGrid1.SelectedObject = file; cwd = openSettingsFileDialog.FileName; } }
static void GenerateNavMesh(string fileName) { NavMeshConfigurationFile file = new NavMeshConfigurationFile(); file.GenerationSettings.AgentRadius = 0.31f; file.ExportPath = fileName + ".snj"; NavMeshConfigurationFile.MeshSettings loadMesh = new NavMeshConfigurationFile.MeshSettings() { Path = fileName + ".obj", Position = new float[3], Scale = 1.0f }; file.InputMeshes.Add(loadMesh); List <string> meshes = new List <string>(); List <ObjModel> models = new List <ObjModel>(); foreach (var mesh in file.InputMeshes) { //Log.("Path: " + mesh.Path, 2); //Log.Debug("Scale: " + mesh.Scale, 2); //Log.Debug("Position: " + mesh.Position.ToString(), 2); meshes.Add(mesh.Path); SharpNav.Geometry.Vector3 position = new SharpNav.Geometry.Vector3(mesh.Position[0], mesh.Position[1], mesh.Position[2]); if (File.Exists(mesh.Path)) { ObjModel obj = new ObjModel(mesh.Path); float scale = mesh.Scale; //TODO SCALE THE OBJ FILE models.Add(obj); } else { //Log.Error("Mesh file does not exist."); return; } } var tris = Enumerable.Empty <SharpNav.Geometry.Triangle3>(); foreach (var model in models) { tris = tris.Concat(model.GetTriangles()); } TiledNavMesh navmesh = NavMesh.Generate(tris, file.GenerationSettings); new NavMeshJsonSerializer().Serialize(file.ExportPath, navmesh); }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { NavMeshConfigurationFile file = propertyGrid1.SelectedObject as NavMeshConfigurationFile; if (file == null) { //MessageBox.Show("Nothing to save"); } else { if (saveSettingsFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { saveprocess(file, saveSettingsFileDialog.FileName); } } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { NavMeshConfigurationFile setting = propertyGrid1.SelectedObject as NavMeshConfigurationFile; if (setting == null) { //MessageBox.Show("Nothing to save"); } else { if (cwd == null) { saveAsToolStripMenuItem_Click(sender, e); } else { saveprocess(setting, cwd); } } }
//TODO remove function now that it's a single line private void saveprocess(NavMeshConfigurationFile file, string location) { file.Save(location); }
static int Main(string[] args) { bool help = false; bool version = false; List <string> files = new List <string>(); var set = new OptionSet() .Add("verbosity=|v=", "Changes verbosity level. Valid options:\ns[ilent]\nm[inimal]\nn[ormal]\nv[erbose]\nd[ebug]", opt => { Log.Verbosity = Verbosity.Parse(opt); }) .Add("version", "Displays version information", opt => version = (opt != null)) .Add("help|h", "Displays usage information", opt => help = (opt != null)); try { files = set.Parse(args); } catch (OptionException) { Log.Error("Invalid option."); Log.WriteLine("usage: sharpnav <OPTIONS> [FILES]"); Log.WriteLine("Avaliable Options:"); set.WriteOptionDescriptions(Console.Out); return(1); } if (help) { Log.WriteLine("usage: sharpnav <OPTIONS> [FILES]"); Log.WriteLine("Available Options:"); set.WriteOptionDescriptions(Console.Out); return(0); } if (version) { Log.WriteLine("SharpNav " + SharpNavVersion); Log.WriteLine("SharpNav.CLI " + ThisVersion); return(0); } if (files.Count == 0) { Log.Error("No configuration files to process."); return(1); } Log.Info("Number of files to parse: " + files.Count); foreach (var f in files) { StreamReader input = null; Log.Info("Parsing file \"" + f + "\""); try { input = new StreamReader(f); } catch (Exception e) { Log.Error("Error opening file \"" + f + "\"."); Log.Debug(e.GetType().ToString() + " thrown:"); Log.Debug(e.StackTrace, 1); return(1); } NavMeshConfigurationFile file = new NavMeshConfigurationFile(input); Log.Debug("Parsed configuration:"); Log.Debug("Cell Size: " + file.GenerationSettings.CellSize, 1); Log.Debug("Cell Height: " + file.GenerationSettings.CellHeight, 1); Log.Debug("Max Climb: " + file.GenerationSettings.MaxClimb, 1); Log.Debug("Agent Height: " + file.GenerationSettings.AgentHeight, 1); Log.Debug("Agent Radius: " + file.GenerationSettings.AgentRadius, 1); Log.Debug("Min Region Size: " + file.GenerationSettings.MinRegionSize, 1); Log.Debug("Merged Region Size: " + file.GenerationSettings.MergedRegionSize, 1); Log.Debug("Max Edge Length: " + file.GenerationSettings.MaxEdgeLength, 1); Log.Debug("Max Edge Error: " + file.GenerationSettings.MaxEdgeError, 1); Log.Debug("Verts Per Poly: " + file.GenerationSettings.VertsPerPoly, 1); Log.Debug("Sample Distance: " + file.GenerationSettings.SampleDistance, 1); Log.Debug("Max Sample Error: " + file.GenerationSettings.MaxSampleError, 1); Log.Debug(""); Log.Debug("Output File: " + file.ExportPath, 1); Log.Debug(""); Log.Debug("Meshes"); List <string> meshes = new List <string>(); List <ObjModel> models = new List <ObjModel>(); foreach (var mesh in file.InputMeshes) { Log.Debug("Path: " + mesh.Path, 2); Log.Debug("Scale: " + mesh.Scale, 2); Log.Debug("Position: " + mesh.Position.ToString(), 2); meshes.Add(mesh.Path); Vector3 position = new Vector3(mesh.Position[0], mesh.Position[1], mesh.Position[2]); if (File.Exists(mesh.Path)) { ObjModel obj = new ObjModel(mesh.Path); float scale = mesh.Scale; //TODO SCALE THE OBJ FILE models.Add(obj); } else { Log.Error("Mesh file does not exist."); return(1); } } var tris = Enumerable.Empty <Triangle3>(); foreach (var model in models) { tris = tris.Concat(model.GetTriangles()); } TiledNavMesh navmesh = NavMesh.Generate(tris, file.GenerationSettings); new NavMeshJsonSerializer().Serialize(file.ExportPath, navmesh); } Log.WriteLine("Done. " + files.Count + " files processed."); #if DEBUG Console.ReadLine(); #endif return(0); }