forked from drewcassidy/KSP-Toolkit
35 lines
1.3 KiB
Python
Executable File
35 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import os
|
|
import os.path
|
|
import tempfile
|
|
import argparse
|
|
import dds
|
|
|
|
parser = argparse.ArgumentParser(description="Converts any number of textures to dds format. automatically chooses dxt1 or dxt5 depending on if the source image has anything in its alpha channel.")
|
|
parser.add_argument('files', type=str, nargs='*', help = "input texture files")
|
|
parser.add_argument('--convertcmd', type=str, metavar='CMD', default="convert", help="name of imagemagick's convert tool (default: %(default)s)")
|
|
parser.add_argument('--compresscmd', type=str, metavar='CMD', default="nvcompress", help="name of the nvidia dds compress tool (default: %(default)s)")
|
|
|
|
args = parser.parse_args()
|
|
|
|
dds.convertcmd = args.convertcmd
|
|
dds.compresscmd = args.compresscmd
|
|
|
|
with tempfile.TemporaryDirectory() as tempDir:
|
|
for argv in args.files:
|
|
print(f'[{argv}]: converting to dds')
|
|
file = os.path.abspath(argv)
|
|
tmpOutput = os.path.join(tempDir, os.path.basename(file))
|
|
output = os.path.splitext(file)[0] + ".dds"
|
|
|
|
alpha = dds.alpha(file)
|
|
dds.flip(file, tmpOutput)
|
|
|
|
if alpha < 255:
|
|
format = "-bc3"
|
|
else:
|
|
format = "-bc1"
|
|
dds.nvcompress(format, tmpOutput, output)
|
|
os.remove(file) |