# Embeds a .glb's externally referenced images into the file itself, which is what Singe's loader # needs: it reads images from buffer views and will not go looking for a file beside the model. # Downloaded packs often ship a .glb that still points at a shared texture atlas (Kenney's arcade # models name "Textures/colormap.png"), and those load untextured until this is run over them. # packGlb.py does the same job for a .gltf with external buffers; this one leaves the buffer alone # and only pulls the images in. # Usage: python3 util/embedGlbImages.py in.glb out.glb [--base DIRECTORY] import argparse import json import os import struct import sys mimeTypes = {'png': 'image/png', 'jpg': 'image/jpeg', 'jpeg': 'image/jpeg', 'ktx2': 'image/ktx2', 'webp': 'image/webp', 'basis': 'image/basis'} parser = argparse.ArgumentParser() parser.add_argument('source') parser.add_argument('output') parser.add_argument('--base', default=None, help='where the external images live (default: beside the source)') args = parser.parse_args() base = args.base if args.base else os.path.dirname(args.source) with open(args.source, 'rb') as f: magic, version, length = struct.unpack('= 8: binLength, binType = struct.unpack('