-
Notifications
You must be signed in to change notification settings - Fork 2
/
genmatlist.py
72 lines (56 loc) · 2.35 KB
/
genmatlist.py
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
import os
import sys
class Application(object):
ignored_directories = ["textures", "commander", "gui"]
material_template = """
singleton Material({name})
{opening}
diffuseMap[0] = "{path}";
mapTo = "{name}";
{closing};
"""
def main(self):
if (len(sys.argv) != 3):
print("Usage: %s <material dir> <output material script>" % sys.argv[0])
print("material dir is the root of the directory in which the Tribes 2 materials can be found.")
print("output material script is the output script for Torque3D that allows proper material usage.")
return
material_directory = sys.argv[1]
output_location = sys.argv[2]
os.chdir(sys.argv[1])
# In this list we store dictionaries that store a name and a path
materials = [ ]
# First, we generate a listing of the T2 matlist
for path, directories, files in os.walk(".", topdown=True):
# Don't recurse textures
if (path == "."):
for exclusion in self.ignored_directories:
try:
directories.remove(exclusion)
except ValueError: pass
continue
for file in files:
if (os.path.isfile(file) is not True):
continue
full_path = os.path.join(path, file)[2:]
material_name = os.path.basename(full_path)
material_name = os.path.splitext(material_name)[0].upper()
material_name = material_name.replace(".", "")
material = { "name": material_name, "path": full_path, "opening": "{", "closing": "}" }
materials.append(material)
# Now dump the output and we should be golden.
try:
with open(output_location, "w") as output_handle:
for material in materials:
output_handle.write(self.material_template.format(**material))
print("Wrote output to %s." % output_location)
except OSError as e:
print("FATAL: Failed to open %s for read or %s for write!" % (input_location, output_location))
if __name__ == "__main__":
Application().main()
#singleton Material( BlankWhite )
#{
# diffuseMap[0] = "core/art/white";
# mapTo = "white";
# materialTag0 = "Miscellaneous";
#};