#!/usr/bin/env python3 """Repair a GLB whose material references a texture with no image source. Blender's WebP glTF export occasionally emits a texture slot whose image failed to encode (no `source`, no `EXT_texture_webp.source`) — e.g. a packed metallic-roughness/AO map. three.js GLTFLoader then throws `Cannot read properties of undefined (reading 'uri')` when a material points at it. This strips every material texture-slot that points at a sourceless texture (base-colour / normal are kept; the orphaned texture is never loaded because GLTFLoader loads textures lazily), then repacks the GLB (BIN chunk untouched). python3 fix_glb_textures.py in.glb out.glb """ import json, struct, sys SLOTS = ("baseColorTexture", "metallicRoughnessTexture", "normalTexture", "occlusionTexture", "emissiveTexture") def read_glb(path): d = open(path, "rb").read() off, gltf, chunks = 12, None, [] while off < len(d): clen, ctype = struct.unpack("