diff options
Diffstat (limited to '')
-rw-r--r-- | ConsoleApp/ModelCommands.cs | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/ConsoleApp/ModelCommands.cs b/ConsoleApp/ModelCommands.cs new file mode 100644 index 0000000..9bbf1f3 --- /dev/null +++ b/ConsoleApp/ModelCommands.cs @@ -0,0 +1,118 @@ +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 <brres-filename> <obj-filename> <model-name> [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 <brres-filename> <obj-filename> <model-name>\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 <brres-filename> <dae-filename> <model-name>\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."; + } + } +} + |