#!/usr/bin/env python3 """Samples embedded GLB base-color textures to representative sRGB colours. Most line GLBs reference a baseColorTexture without a baseColorFactor, so the material colour cannot be read from the JSON alone. This script decodes each embedded image with Pillow, averages it (after downsampling), multiplies by the factor when present, and writes material-colors.json for build-line-spec.mjs. Usage: python3 -I sample-material-colors.py [sourceDir] [outFile] """ import io import json import os import struct import sys from PIL import Image here = os.path.dirname(os.path.abspath(__file__)) source_dir = sys.argv[1] if len(sys.argv) > 1 else "/home/mes123456/FreeCADWasmDev/working/GLTFmodel" out_file = sys.argv[2] if len(sys.argv) > 2 else os.path.join(here, "material-colors.json") def read_glb(path): with open(path, "rb") as handle: handle.read(12) gltf = None binary = b"" while True: header = handle.read(8) if len(header) < 8: break length, kind = struct.unpack("