Spaces:
Running
Running
File size: 1,041 Bytes
2d77bd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | """Blender (5.x) script: shrink a scene GLB for the web viewer.
Run: Blender -b --factory-startup --python tools/blender_scene_glb.py -- <in.glb> <out.glb> [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")
|