File size: 1,656 Bytes
0aefd10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""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)}")