| | """
|
| | 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:
|
| |
|
| | argv = sys.argv[sys.argv.index("--") + 1:]
|
| | input_fbx = Path(argv[0])
|
| | output_glb = Path(argv[1])
|
| |
|
| |
|
| | if not input_fbx.exists():
|
| | raise FileNotFoundError(f"Input FBX file not found: {input_fbx}")
|
| |
|
| |
|
| | clean_scene()
|
| |
|
| |
|
| | print(f"Importing {input_fbx}...")
|
| | bpy.ops.import_scene.fbx(filepath=str(input_fbx))
|
| |
|
| |
|
| | print(f"Exporting to {output_glb}...")
|
| | bpy.ops.export_scene.gltf(
|
| | filepath=str(output_glb),
|
| | export_format='GLB',
|
| | export_skins=True,
|
| | export_texcoords=False,
|
| | export_normals=False,
|
| | export_colors=False,
|
| | )
|
| |
|
| | print("Conversion completed successfully")
|
| |
|
| | except Exception as e:
|
| | print(f"Error: {str(e)}")
|
| | sys.exit(1)
|
| |
|
| |
|
| | if __name__ == "__main__":
|
| | main() |