"""
SURYA - Alembic Export Script
Exports all scenes from surya_all.blend as individual Alembic (.abc) files.

Usage:
    /Applications/Blender.app/Contents/MacOS/Blender surya_all.blend --background --python export_alembic.py
"""

import bpy
import os

SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
EXPORTS_DIR = os.path.join(SCRIPT_DIR, "exports")

def export_all_alembic():
    """Export each scene as an Alembic file."""
    os.makedirs(EXPORTS_DIR, exist_ok=True)
    
    print("=" * 60)
    print("SURYA - Alembic Export")
    print("=" * 60)
    
    exported = []
    failed = []
    
    for scene in bpy.data.scenes:
        scene_name = scene.name
        print(f"\nExporting: {scene_name}...")
        
        # Set as active scene
        bpy.context.window.scene = scene
        
        abc_path = os.path.join(EXPORTS_DIR, f"{scene_name}.abc")
        
        try:
            bpy.ops.wm.alembic_export(
                filepath=abc_path,
                start=scene.frame_start,
                end=scene.frame_end,
                xsamples=1,
                gsamples=1,
                sh_open=0.0,
                sh_close=1.0,
                export_hair=False,
                export_particles=False,
                flatten=False,
                selected=False,
                export_normals=True,
                export_uvs=True,
                export_custom_properties=True,
                visible_objects_only=True,
            )
            print(f"  ✓ Exported: {abc_path}")
            exported.append(scene_name)
        except Exception as e:
            print(f"  ✗ Failed: {e}")
            failed.append((scene_name, str(e)))
    
    # Summary
    print("\n" + "=" * 60)
    print("ALEMBIC EXPORT SUMMARY")
    print("=" * 60)
    print(f"\nSuccessful: {len(exported)}")
    for name in exported:
        print(f"  ✓ {name}.abc")
    
    if failed:
        print(f"\nFailed: {len(failed)}")
        for name, error in failed:
            print(f"  ✗ {name}: {error}")
    
    print(f"\nOutput directory: {EXPORTS_DIR}")


if __name__ == "__main__":
    export_all_alembic()
