"""Blender (5.x) script: shrink a scene GLB for the web viewer. Run: Blender -b --factory-startup --python tools/blender_scene_glb.py -- [max_texture_px] Re-exports with textures downsized (JPEG) and Draco-compressed geometry; layout, materials and object names stay as they are. """ import sys import bpy args = sys.argv[sys.argv.index("--") + 1:] src, out = args[0], args[1] max_px = int(args[2]) if len(args) > 2 else 2048 bpy.ops.wm.read_factory_settings(use_empty=True) bpy.ops.import_scene.gltf(filepath=src) for img in bpy.data.images: w, h = img.size if max(w, h) > max_px: s = max_px / max(w, h) img.scale(max(1, int(w * s)), max(1, int(h * s))) bpy.ops.export_scene.gltf( filepath=out, export_format="GLB", export_yup=True, export_apply=True, export_draco_mesh_compression_enable=True, export_draco_mesh_compression_level=6, export_image_format="JPEG", export_image_quality=82, export_cameras=False, export_lights=False, export_animations=False, ) print("SCENE_OK")