Convert glTF images to ktx using https://github.com/cdwfs/img2ktx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import argparse | |
import sys | |
import os | |
import subprocess | |
parser = argparse.ArgumentParser(description='Convert a glTF file textures to the ktx format') | |
parser.add_argument('--input', type=str, help='glTF file') | |
parser.add_argument('--output', type=str, help='Filename for updated glTF file') | |
parser.add_argument('--format', type=str, help='KTX format') | |
args = parser.parse_args() | |
if args.input == None: | |
sys.exit("No input file specified") | |
if args.input != None: | |
output_format = args.format | |
else: | |
output_format = "RGBA" | |
input_file = args.input | |
output_file = "" | |
if args.output != None: | |
output_file = args.output | |
if not os.path.isfile(input_file): | |
sys.exit("File does not exist") | |
with open(input_file) as json_file: | |
data = json.load(json_file) | |
for image in data['images']: | |
input_image_file = image['uri'] | |
output_image_file = os.path.splitext(input_image_file)[0] + ".ktx" | |
if os.path.isfile(input_image_file): | |
print("Converting %s" % input_image_file) | |
subprocess.check_output([ | |
"img2ktx", | |
"-f", output_format, | |
"-m", | |
"-o", output_image_file, | |
input_image_file | |
]) | |
image['uri'] = output_image_file | |
if output_file != "": | |
with open(output_file, 'w') as outfile: | |
json.dump(data, outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment