-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdds.py
executable file
·151 lines (135 loc) · 4.57 KB
/
dds.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
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
145
146
147
148
149
150
151
#!/usr/bin/python
# Usage:
#
# ./dds.py /path/to/GameData
#
# or just
#
# ./dds.py
#
# in case this is located inside KSP directory.
# The following regex patterens must match the beginning of a texture path (after `GameData/`).
# Excluded texture patterns. These textures will be left intact.
EXCLUDE = [
'BoulderCo/',
'CapCom/Textures/CapComToolbarIcon',
'CommunityResourcePack/',
'ContractRewardModifier/Textures/ContractModifierToolbarIcon',
'ContractsWindow/Textures/ContractsIcon',
'CustomBiomes/PluginData/CustomBiomes/',
'Diazo/AGExt/',
'KittopiaSpace/',
'Kopernicus',
'OPM/',
'MagicSmokeIndustries/Textures/',
'NavyFish/Plugins/PluginData/',
'NearFuture.*/(Icons|PluginData)/',
'Olympic1ARPIcons/',
'RCSBuildAid/Textures/iconAppLauncher',
'RealChute/Plugins/PluginData/',
'RealSolarSystem/Plugins/PluginData/',
'SCANsat/Icons/',
'scatterer/',
'Squad/Contracts/Icons/',
'TextureReplacer/EnvMap/',
'TriggerTech/.*/(Icons|Textures|ToolbarIcons)/',
'UmbraSpaceIndustries/Kolonization/OrbitalLogistics',
'UmbraSpaceIndustries/Kolonization/StationManager',
'UmbraSpaceIndustries/LifeSupport/Supplies',
'WarpPlugin/PlanetResourceData/'
]
# Model texture patterns (mipmaps are generated, checked for normal maps).
MODEL = [
'.*/FX/',
'.*/Part/',
'.*/Parts/',
'.*/part/',
'.*/parts/',
'.*/Props/',
'.*/Spaces/',
'ART/',
'ASET/'
'ASET_Props/',
'BobCatind/JoolV/',
'BoulderCo/',
'BoxSat alpha/',
'FASA/',
'JSI/RasterPropMonitor/Library/Components/MFD40x20v2/',
'KAS/Textures/',
'KerbalScienceFoundation/Mk3Cockpit/',
'Kopernicus',
'KSO/RPM/KSO_PROP/',
'KSO/RPM/KSO_Laptop_1/KSOS_Laptop\.',
'KSO/RPM/KSO_Laptop_1/KSOS_Laptop_emis\.',
'KSO/RPM/KSO_Laptop_1/KSOS_Laptop_norm_NRM\.',
'Lionhead_Aerospace_Inc/',
'Part Revamp Extras/',
'ProceduralFairings/',
'Regolith/Assets/',
'RetroFuture/',
'SnacksPartsByWhyren/',
'Space Factory Ind/',
'TantaresLV/',
'TextureReplacer/',
'UmbraSpaceIndustries/',
'VenStockRevamp/Squad/SPP/',
'WildBlueIndustries/MCM/MultiModule/'
]
# Some non-model textures may match the previous model patterns. Exclude them from models.
NOT_MODEL = [
'.*/Agencies/',
'.*/Flags/',
'.*/Icons/',
'.*/Props/(Fonts|Screens)/',
'ASET_Props/MFDs/',
'AxialAerospace/Props/.*\.png$',
'B9_Aerospace/Props/B9_MFD/images/',
'HOME2/Props/.*\.png',
'KIS/Parts/guide/page.*\.png$',
'Kopernicus.*height\.png',
'Space Factory Ind/.*/JSI/.*\.png$',
'TextureReplacer/Default/(HUD|IVA)NavBall',
'TextureReplacer/Plugins',
'UmbraSpaceIndustries/Kolonization/MKS/Assets/(OrbLogisticsIcon|StationManager)'
]
# Scale for model textures.
MODEL_SCALE = 1.0
# Scale for model normal maps.
MODEL_NORMALS_SCALE = 1.0
# Uncomment to shrink normal maps to ~ 1/2 size; i.e. 1024 -> 720, 512 -> 360, 256 -> 180 etc.
#MODEL_NORMALS_SCALE = 0.703125
####################################################################################################
import os, re, sys
EXCLUDE = [re.compile(e) for e in EXCLUDE]
MODEL = [re.compile(m) for m in MODEL]
NOT_MODEL = [re.compile(m) for m in NOT_MODEL]
IMAGE = re.compile('.*\.(png|PNG|jpg|JPG|tga|TGA|mbm|MBM)$')
NORMAL = re.compile('.*(NRM|_nm|_normal)\....$')
PREFIX = re.compile('.*GameData/')
SYSTEM = 'linux64' if sys.maxsize > 2**32 else 'linux32'
SYSTEM = 'win32' if sys.platform == 'win32' else SYSTEM
SYSTEM = 'osx64' if sys.platform == 'darwin' else SYSTEM
IMG2DDS = './img2dds/' + SYSTEM + '/img2dds'
IMG2DDS = 'img2dds\win32\img2dds.exe' if SYSTEM == 'win32' else IMG2DDS
DIR = sys.argv[1] if len(sys.argv) == 2 else './GameData'
BASEDIR = re.compile('^(.*GameData).*').sub('\\1', DIR)
for (dirPath, dirNames, fileNames) in os.walk(DIR):
dirPath = PREFIX.sub('', dirPath.replace('\\', '/'))
images = {(dirPath + '/' + name) for name in fileNames if IMAGE.match(name)}
images -= {i for i in images for e in EXCLUDE if e.match(i)}
models = {i for i in images for m in MODEL if m.match(i)}
models -= {i for i in images for m in NOT_MODEL if m.match(i)}
normals = {i for i in models if NORMAL.match(i)}
for i in images:
path = BASEDIR + '/' + i
isNormal = i in normals or os.system(IMG2DDS + ' -N "' + path + '"') == 0
options = '-vc'
if i in models:
options += 'mnsr ' + str(MODEL_NORMALS_SCALE) if isNormal else 'mr ' + str(MODEL_SCALE)
if os.system(IMG2DDS + ' ' + options + ' "' + path + '"') == 0:
os.remove(path)
else:
print('FAILED to convert ' + path)
if SYSTEM == 'win32' and not sys.stdin.closed:
print('Finished. Press Enter to continue ...')
sys.stdin.readline()