forked from brihernandez/FLTextureExporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportmat.cs
57 lines (50 loc) · 2.06 KB
/
exportmat.cs
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
using System.IO;
using System.Linq;
if(Arguments.Length < 2) {
Console.Error.WriteLine("usage: matexport.cs outputdir/ file.mat ... ");
return;
}
var directory = Arguments[0];
Directory.CreateDirectory(directory);
int exportTotal = 0;
for (int i = 1; i < Arguments.Length; ++i)
{
var file = Arguments[i];
if(!File.Exists(file)) {
Console.Error.WriteLine($"Could not open file {file}");
continue;
}
var mat = new EditableUtf(file);
foreach(var node in mat.Root.IterateAll()) {
if(node.Name.Equals("texture library", StringComparison.OrdinalIgnoreCase)) {
Console.WriteLine($"\n{Path.GetFileName(file)}");
exportTotal = node.Children.Count;
foreach(var t in node.Children) {
var mips = t.Children.FirstOrDefault(x => x.Name.Equals("MIPS", StringComparison.OrdinalIgnoreCase));
if(mips != null) {
var fileName = Path.Combine(directory, t.Name + ".dds");
File.WriteAllBytes(fileName, mips.Data);
Console.WriteLine(" " + Path.GetFileName(fileName));
exportTotal += 1;
} else {
var mip0 = t.Children.FirstOrDefault(x => x.Name.Equals("MIP0", StringComparison.OrdinalIgnoreCase));
if (mip0 != null){
var fileName = Path.Combine(directory, $"{t.Name}.tga");
File.WriteAllBytes(fileName, mip0.Data);
Console.WriteLine(" " + Path.GetFileName(fileName));
exportTotal += 1;
}
}
}
}
}
}
if (exportTotal == 0){
Console.WriteLine($"\nNo {Path.GetExtension(Arguments[1])}s with textures found in {Path.GetDirectoryName(Arguments[1])}");
try {
Directory.Delete(directory);
} catch (System.IO.IOException) { }
}
else {
Console.WriteLine($"\nExported {exportTotal} total textures from {Path.GetDirectoryName(Arguments[1])}");
}