Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert glTF images to ktx using
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
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)
"-f", output_format,
"-o", output_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