Spaces:
Running
Running
Download tools/blender_glb.py from projectsim/simready-library: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/projectsim/simready-library/resolve/main/tools/blender_glb.py
- Command line
-
hf download hf://spaces/projectsim/simready-library/tools/blender_glb.py
-
curl -L -o blender_glb.py https://huggingface.co/spaces/projectsim/simready-library/resolve/main/tools/blender_glb.py
1.66 kB
| """Blender (5.x) script: one SimReady USD -> a small web preview GLB. | |
| Run: Blender -b --factory-startup --python tools/blender_glb.py -- <in.usd> <out.glb> [max_texture_px] | |
| Keeps render geometry and materials, drops collision and guide geometry, downsizes | |
| textures, and writes a Draco-compressed, Y-up GLB. Object names come from the USD prim | |
| names, which the viewer uses to find each moving part. | |
| """ | |
| 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 1024 | |
| bpy.ops.wm.read_factory_settings(use_empty=True) | |
| bpy.ops.wm.usd_import(filepath=src, import_guide=False, import_proxy=False, import_render=True, | |
| import_usd_preview=True, import_visible_only=True) | |
| def is_collision(obj): | |
| o = obj | |
| while o is not None: | |
| if "collision" in o.name.lower() or "collider" in o.name.lower(): | |
| return True | |
| o = o.parent | |
| return False | |
| doomed = [o for o in bpy.data.objects if o.type == "MESH" and is_collision(o)] | |
| for o in doomed: | |
| bpy.data.objects.remove(o, do_unlink=True) | |
| 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=85, | |
| export_cameras=False, export_lights=False, export_animations=False, | |
| ) | |
| print(f"PREVIEW_OK removed_collision_meshes={len(doomed)}") | |