企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## **伍、整合** **H子:** 好的老师,等我自己来完整的设计一次代码吧,你只要看着我就行了。 **AOI:** 这么主动?真少见呢。 **H子:** 哼哼,条件已经齐备,我非常信心一口气的搞定。看我的: ~~~python import bpy #定义导出路径 savePath = "c:/tmp/TestExport/" #保存选中对象 objs = bpy.context.selected_objects print(objs) #遍历 for o in objs: #清除全选并按名称选中对象 bpy.ops.object.select_all(action='DESELECT') bpy.data.objects[o.name].select = True #保存清零变换前的对象变换参数 s_Locx = bpy.data.objects[o.name].location.x s_Locy = bpy.data.objects[o.name].location.y s_Locz = bpy.data.objects[o.name].location.z s_rotx = bpy.data.objects[o.name].rotation_euler.x s_roty = bpy.data.objects[o.name].rotation_euler.y s_rotz = bpy.data.objects[o.name].rotation_euler.z s_scax = bpy.data.objects[o.name].scale.x s_scay = bpy.data.objects[o.name].scale.y s_scaz = bpy.data.objects[o.name].scale.z #清零变换 bpy.ops.object.location_clear(clear_delta=False) bpy.ops.object.scale_clear(clear_delta=False) bpy.ops.object.rotation_clear(clear_delta=False) #导出模型 bpy.ops.export_scene.fbx(filepath=savePath + o.name + ".fbx",axis_forward='-Z', axis_up='Y',version='BIN7400',use_selection=True,bake_space_transform=True, object_types={'MESH'})。 #还原模型变换 bpy.data.objects[o.name].location.x = s_Locx bpy.data.objects[o.name].location.y = s_Locy bpy.data.objects[o.name].location.z = s_Locz bpy.data.objects[o.name].rotation_euler.x = s_rotx bpy.data.objects[o.name].rotation_euler.y = s_roty bpy.data.objects[o.name].rotation_euler.z = s_rotz bpy.data.objects[o.name].scale.x = s_scax bpy.data.objects[o.name].scale.y = s_scay bpy.data.objects[o.name].scale.z = s_scaz ~~~ 全选模型之后执行,成功的在目标文件夹导出了模型 ![](https://box.kancloud.cn/e605f9abc3c1fa53990bae841351c573_675x328.png)