File size: 1,806 Bytes
ef5c6d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
"""

Copyright (c) 2024-2025, The Alibaba 3DAIGC Team Authors.



Blender FBX to GLB Converter

Converts 3D models from FBX to glTF Binary (GLB) format with optimized settings.

Requires Blender to run in background mode.

"""

import bpy
import sys
from pathlib import Path

def clean_scene():
    """Clear all objects and data from the current Blender scene"""
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.delete()
    for collection in [bpy.data.meshes, bpy.data.materials, bpy.data.textures]:
        for item in collection:
            collection.remove(item)


def main():
    try:
        # Parse command line arguments after "--"
        argv = sys.argv[sys.argv.index("--") + 1:]
        input_fbx = Path(argv[0])
        output_glb = Path(argv[1])

        # Validate input file
        if not input_fbx.exists():
            raise FileNotFoundError(f"Input FBX file not found: {input_fbx}")

        # Prepare scene
        clean_scene()

        # Import FBX with default settings
        print(f"Importing {input_fbx}...")
        bpy.ops.import_scene.fbx(filepath=str(input_fbx))

        # Export optimized GLB
        print(f"Exporting to {output_glb}...")
        bpy.ops.export_scene.gltf(
            filepath=str(output_glb),
            export_format='GLB',          # Binary format
            export_skins=True,            # Keep skinning data
            export_texcoords=False,       # Reduce file size
            export_normals=False,         # Reduce file size
            export_colors=False,          # Reduce file size
        )

        print("Conversion completed successfully")

    except Exception as e:
        print(f"Error: {str(e)}")
        sys.exit(1)


if __name__ == "__main__":
    main()