using System; using System.Collections.Generic; using System.IO; using NW4RTools; namespace ConsoleApp { public class ImportObjCommand : ResFileCommand { public ImportObjCommand() : base("import an .obj model and associated textures") { } protected override void OperateOnFile(string[] args) { if (args.Length < 2 || args.Length > 3) { Console.WriteLine("invalid syntax.\n" + GetHelp(null)); return; } string currentDir = Directory.GetCurrentDirectory(); string objPath = Path.Combine(currentDir, args[0]); string objDir = Path.GetDirectoryName(objPath); ObjImporter.LightmapType lmType = ObjImporter.LightmapType.None; if (args.Length == 3 && args[2] != "none") { switch (args[2]) { case "map": lmType = ObjImporter.LightmapType.Map; break; case "mapobj": lmType = ObjImporter.LightmapType.MapObj; break; default: Console.WriteLine("warning: unknown lightmap type {0}", args[2]); break; } } Console.WriteLine("importing model..."); ObjImporter.ImportModel(objDir, new StreamReader(objPath), TargetFile, args[1], lmType); Console.WriteLine("saving file..."); SaveFile(); Console.WriteLine("done!"); } public override string GetHelp(string[] args) { return "syntax: import-obj [lightmap-mode]\n" + " imports an .obj model and the associated textures.\n\n" + " model-name will be the name of the ResMdl.\n" + " lightmap-mode may be: none (default), map, mapobj"; } } public class ExportObjCommand : ResFileCommand { public ExportObjCommand() : base("export an .obj model") { } protected override void OperateOnFile(string[] args) { if (args.Length != 2) { Console.WriteLine("invalid syntax.\n" + GetHelp(null)); return; } string currentDir = Directory.GetCurrentDirectory(); string objPath = Path.Combine(currentDir, args[0]); string objDir = Path.GetDirectoryName(objPath); Console.WriteLine("exporting model..."); ObjExporter.WriteModel(new StreamWriter(objPath), TargetFile, args[1]); Console.WriteLine("done!"); } public override string GetHelp(string[] args) { return "syntax: export-obj \n" + " exports a model as .obj.\n\n" + " model-name will be the name of the ResMdl.\n" + " more settings will be added later."; } } public class ExportColladaCommand : ResFileCommand { public ExportColladaCommand() : base("export a COLLADA (.dae) model") { } protected override void OperateOnFile(string[] args) { if (args.Length != 2) { Console.WriteLine("invalid syntax.\n" + GetHelp(null)); return; } string currentDir = Directory.GetCurrentDirectory(); string daePath = Path.Combine(currentDir, args[0]); string daeDir = Path.GetDirectoryName(daePath); Console.WriteLine("exporting model..."); ColladaExporter.WriteModel(File.OpenWrite(daePath), TargetFile, args[1]); Console.WriteLine("done!"); } public override string GetHelp(string[] args) { return "syntax: export-collada \n" + " exports a model as COLLADA (.dae).\n\n" + " model-name will be the name of the ResMdl.\n" + " more settings will be added later."; } } public class RenderModelCommand : ResFileCommand { public RenderModelCommand() : base("render a model in a window using OpenGL") { } protected override void OperateOnFile(string[] args) { if (args.Length != 1) { Console.WriteLine("invalid syntax.\n" + GetHelp(null)); return; } using (var rwin = new RenderWindow()) { rwin.Title = args[0]; rwin.SetModel(TargetFile, args[0]); rwin.Run(1, 1); } } public override string GetHelp(string[] args) { return "syntax: render-model \n" + " renders a model in a window using OpenGL.\n\n" + " quite limited at the moment, will be improved later"; } } }