1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
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.";
}
}
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 <brres-filename> <model-name>\n"
+ " renders a model in a window using OpenGL.\n\n"
+ " quite limited at the moment, will be improved later";
}
}
}
|