"""Build packed, geometry-first derivatives of the already-public homepage models.""" import concurrent.futures, copy, hashlib, io, json, struct, urllib.request from pathlib import Path from PIL import Image ROOT=Path(__file__).resolve().parent.parent OUT=ROOT/'models/progressive-v1';OUT.mkdir(parents=True,exist_ok=True) import tempfile CACHE=Path(tempfile.gettempdir())/'c4s-progressive-models';CACHE.mkdir(exist_ok=True) KEY=bytes.fromhex('5c2f9e71d3a84b06e1f7c29a38d05b64a7193ce8f2046db95e81c73a2df6904b') def pack(b):return bytes(v^KEY[i&31]^(((i>>5)*131)&255) for i,v in enumerate(b)) def convert(url): name=url.split('/')[-1].split('?')[0];p=CACHE/name if not p.exists(): with urllib.request.urlopen('https://simworld-ai-code4scene.static.hf.space/'+url,timeout=90) as r:p.write_bytes(r.read()) original=pack(p.read_bytes());assert original[:4]==b'glTF' n=struct.unpack_from('512: img.thumbnail((512,512),Image.Resampling.LANCZOS);dest=io.BytesIO();img.save(dest,format='WEBP',quality=85,method=4);b=dest.getvalue() width,height=img.size images.append((i,b,width,height));del im['bufferView'];im['uri']='deferred-image-'+str(i);im['mimeType']='image/webp' texture_bytes=0;bundles=[] # Small batches avoid hundreds of HTTP requests and permit visible incremental updates. for start in range(0,len(images),32): group=images[start:start+32];data=b''.join(x[1] for x in group);digest=hashlib.sha256(data).hexdigest()[:24];filename='tex-'+digest+'.bin' (OUT/filename).write_bytes(pack(data));bundles.append(filename);texture_bytes+=len(data);offset=0 for i,b,w,h in group: g['images'][i].setdefault('extras',{})['c4sTexture']={'bundle':filename,'offset':offset,'length':len(b),'width':w,'height':h};offset+=len(b) while len(payload)%4:payload.append(0) g['buffers'][0]['byteLength']=len(payload) header=json.dumps(g,separators=(',',':'),ensure_ascii=False).encode();header+=b' '*((-len(header))%4) glb=struct.pack('