"""One FBX per part into fbx/: the part at the origin, its moving rod (if any) as a child, its UCX boxes. Settings as models/pressure-door/build/pd_export.py (Z up, -Y forward, metres).""" import os import json import bpy def run(out): folder = os.path.join(out, "fbx") os.makedirs(folder, exist_ok=True) roots = [o for o in bpy.data.objects if o.name.startswith("SM_Kit_") and o.parent is None] done = [] for r in sorted(roots, key=lambda o: o.name): keep = r.location.copy() r.location = (0, 0, 0) group = [r] + [c for c in r.children_recursive] for o in bpy.context.view_layer.objects: o.select_set(o in group) bpy.context.view_layer.objects.active = r path = os.path.join(folder, r.name + ".fbx") bpy.ops.export_scene.fbx(filepath=path, use_selection=True, object_types={"MESH"}, use_mesh_modifiers=False, mesh_smooth_type="OFF", add_leaf_bones=False, bake_anim=False, axis_forward="-Y", axis_up="Z", global_scale=1.0, apply_unit_scale=True, apply_scale_options="FBX_SCALE_NONE", use_space_transform=True, bake_space_transform=False, path_mode="STRIP", use_metadata=False, use_tspace=True) r.location = keep done.append(dict(file=os.path.basename(path), objects=[o.name for o in group], kb=round(os.path.getsize(path) / 1024))) with open(os.path.join(out, "fbx", "export_list.json"), "w") as f: json.dump(done, f, indent=1) print("EXPORT", len(done))