Blender软件将工程中的模型批量导出成fbx格式
使用场景:
blend项目文件中有上百个模型图层元素,你想一一导出成fbx格式的模型,手动肯定会累死人,你可以利用我提供的脚本,一键全部导出。
1.首先需要把项目另存为.blender工程文件。
2.打开blend文件,选中需要导出的模型元素
3.然后在菜单Scripting中,新建一个脚本,把下面的脚本粘贴,然后运行即可。
# exports every single object to single fbx file. # Copyright https://www.c4d.com # Compatible with Blender 3.5.1 ### fbx files in dir of .blender ### ### bake_space_transform=True,Apply Transform, Bake space transform into object data, avoids getting unwanted rotations to objects when target space is not aligned with Blender’s space (WARNING! experimental option, use at own risk, known to be broken with armatures/animations) ### import bpy import os # export to blend file location basedir = os.path.dirname(bpy.data.filepath) print("START Output path = "+basedir) if not basedir: raise Exception("Blend file is not saved") objects = bpy.context.collection.objects def exportfunc(objName): name = bpy.path.clean_name(objName) fn = os.path.join(basedir, name) # Export gltf # bpy.ops.export_scene.gltf(filepath=fn + ".gltf", export_format="GLTF_SEPARATE", export_lights=False, use_selection=True) # Export fbx bpy.ops.export_scene.fbx(filepath=fn + ".fbx", use_selection=True,bake_space_transform=True) print("written:", fn) return #Deselect all objects for obj in objects: obj.select_set(False) print("===Start save files===") for obj in objects: if obj.parent == None: if obj.type == 'EMPTY' and len(obj.children) > 0: obj.select_set(True) for subObj in obj.children: subObj.select_set(True) # some exporters only use the active object #view_layer.objects.active = obj exportfunc(obj.name) #Deselect all objects for obj in objects: obj.select_set(False) else: obj.select_set(True) exportfunc(obj.name) obj.select_set(False) print("All save completed!")