-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathautomaterials.py
executable file
·67 lines (45 loc) · 1.42 KB
/
automaterials.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
#!/usr/bin/env python3
import re
from pathlib import Path
from collections import defaultdict
from taiseilib.common import (
run_main,
)
mat_re = re.compile(r'(.*)_(diffuse|normal|ambient|roughness)\.(?:tex|basis|png|webp)$')
def main(args):
resdir = Path(__file__).parent.parent / 'resources'
materials = defaultdict(set)
gfxdirs = []
for pkgdir in resdir.glob('*.pkgdir'):
gfx = pkgdir / 'gfx'
if not gfx.is_dir():
continue
gfxdirs.append(gfx)
print(gfx)
for p in gfx.glob('**/*'):
rel = p.relative_to(gfx)
m = mat_re.match(str(rel))
if m is None:
continue
matname, mapname = m.groups()
materials[matname].add(mapname)
gfxmain = gfxdirs[0]
for mat, maps in materials.items():
mat_filename = f'{mat}.material'
skip = False
for gfx in gfxdirs:
if (gfx / mat_filename).exists():
print(' - Skip', mat_filename)
skip = True
break
if skip:
continue
outpath = (gfxmain / mat_filename).resolve()
lines = ['']
for mapname in sorted(maps):
lines.append(f'{mapname}_map = {mat}_{mapname}')
lines.append('')
print(' * Write', outpath)
outpath.write_text('\n'.join(lines))
if __name__ == '__main__':
run_main(main)