-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump3dotx
executable file
·70 lines (57 loc) · 1.98 KB
/
dump3dotx
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
#!/usr/bin/env python
import os, sys
import lecFormats
import lecFormats.grimCmpList
# Grab the cmp file mapping for grim
cmpMap = lecFormats.grimCmpList.cmpMap
def parseArgs():
# TODO: really? I'm too lazy for argparse?
try:
inFile = sys.argv[1]
outDir = sys.argv[2]
except IndexError:
msg = "ERROR: you must specify one 3do file in and a directory "
msg += "to export to"
print >> sys.stderr, msg
sys.exit(1)
if not os.path.exists(outDir):
msg = "ERROR: the output directory must be an existing directory"
print >> sys.stderr, msg
sys.exit(1)
return (None, [inFile, outDir])
def main():
options, args = parseArgs()
modlBasename = os.path.basename(args[0])
modlFolder = os.path.dirname(args[0])
# Build the place to export textures to
assetName = os.path.splitext(modlBasename)[0]
txDir = os.path.join(args[1], assetName, 'textures')
if not os.path.exists(txDir):
os.makedirs(txDir)
# Get a cmp for the 3do
try:
cmpPath = os.path.join(modlFolder, cmpMap[modlBasename])
except KeyError:
msg = "ERROR: unable to determine cmp palette file"
print >> sys.stderr, msg
sys.exit(1)
palette = lecFormats.CmpFile(cmpPath)
# Get the material list for the 3do
modl = lecFormats.ModlFile(args[0])
materials = modl.materials
del(modl)
# Convert each material
for mat_name in materials:
matFile = lecFormats.MatFile(os.path.join(modlFolder, mat_name))
for i,texture in enumerate(matFile.textures):
# build up the path to write the texture file to
txfn = os.path.splitext(mat_name)[0]
if matFile.count > 1:
txfn += '-'+str(i)
txfn += '.tif'
txPath = os.path.join(txDir, txfn)
txImg = texture.textureImage(palette)
txImg.save(txPath)
del(txImg)
if __name__ == "__main__":
main()