描述:3D角色做完把模型给动作,然后动作做完需要导出fbx到unity,当有大量的动作需要导出的时候,对动作来说是非常痛苦的,所以根据动作max文件的储存路劲与max的命名,做了一个批量导出工具。这里将导出类型分成NPC,body,face,head,可以根据自己的项目进行更改。工具截图如下:
代码如下
macroscript 批量导出category:"批量导出" toolTip:"" ( rollout Export "动作批量导出插件" width:215 height:296 ( edittext importPath "导入路径" pos:[7,31] width:197 height:19 label Label01 "动作批量导出插件" pos:[60,4] width:107 height:20 button ExportSkin "导出蒙皮" pos:[33,225] width:66 height:34 edittext exportPath "导出路径" pos:[10,130] width:192 height:20 checkbox body "body" pos:[20,62] width:56 height:16 enabled:true checked:false checkbox head "head" pos:[81,61] width:43 height:15 enabled:true checkbox NPC "NPC" pos:[21,89] width:60 height:18 checkbox face "face" pos:[139,61] width:41 height:16 button ExportAni "导出动作" pos:[120,226] width:66 height:34 on ExportSkin pressed do ( body_int=0 head_int =0 face_int=0 NPC_int=0 if importPath.text.count != 0 and exportPath.text.count!=0 and (head.state!=false or body.state!=false or NPC.state!=false or face.state !=false) then ( importFiles = getFiles(importPath.text+"\\*"+".max") savefilepath = () --如果设置了导出身体 if body.state == true then ( for f in importFiles do ( loadMaxFile f quiet:true arrayExportbody = #() for i in $*body do ( if (i.isHidden == false) then append arrayExportbody i --将以body结尾的所有物体加入数组 ) if arrayExportbody.count != 0 then ( body_int+=1 for i in geometry do i.isHidden = true --隐藏所有的物体 for i in arrayExportbody do ( i.isHidden =false -- 先将第一个身体显示,此时应该只有第一个身体还有骨骼 没其他任何物件 max select all filename = i.name savefilepath = exportPath.text exfile = savefilepath +"\\"+ filename FbxExporterSetParam"Animation" false FbxExporterSetParam "BakeAnimation"false Exportfile exfile #noPrompt using:exporterPlugin.classes[8] i.isHidden =true ) shellLaunch savefilepath"" ) ) ) --如果设置了导出头部 else if head.state== true then ( for f in importFiles do ( loadMaxFile f quiet:true arrayExporthead = #() for i in $*head do ( if (i.isHidden == false) then append arrayExporthead i --将以body结尾的所有物体加入数组 ) if arrayExporthead.count != 0 then ( head_int+=1 for i in geometry do i.isHidden = true --隐藏所有的物体 for i in arrayExporthead do ( i.isHidden =false -- 先将第一个身体显示,此时应该只有第一个身体还有骨骼 没其他任何物件 max select all filename = i.name savefilepath = exportPath.text exfile = savefilepath +"\\"+ filename FbxExporterSetParam"Animation" false FbxExporterSetParam "BakeAnimation"false Exportfile exfile #noPrompt using:exporterPlugin.classes[8] i.isHidden =true ) shellLaunch savefilepath"" ) ) ) else if face.state== true then ( for f in importFiles do ( loadMaxFile f quiet:true arrayExportface = #() for i in $*face do ( if (i.isHidden == false) then append arrayExportface i --将以body结尾的所有物体加入数组 ) if arrayExportface.count != 0 then ( face_int+=1 for i in geometry do i.isHidden = true --隐藏所有的物体 for i in arrayExportface do ( i.isHidden =false -- 先将第一个身体显示,此时应该只有第一个身体还有骨骼 没其他任何物件 max select all filename = i.name savefilepath = exportPath.text exfile = savefilepath +"\\"+ filename FbxExporterSetParam"Animation" false FbxExporterSetParam "BakeAnimation"false Exportfile exfile #noPrompt using:exporterPlugin.classes[8] i.isHidden =true ) shellLaunch savefilepath"" ) ) ) else if NPC.state == true then ( for f in importFiles do ( loadMaxFile f quiet:true arrayExportNPC = #() for i in $NPC* do ( if (i.isHidden == false) then append arrayExportNPC i --将以body结尾的所有物体加入数组 ) if arrayExportNPC.count != 0 then ( NPC_int+=1 for i in geometry do i.isHidden = true --隐藏所有的物体 for i in arrayExportNPC do ( i.isHidden =false -- 先将第一个身体显示,此时应该只有第一个身体还有骨骼 没其他任何物件 max select all filename = i.name savefilepath = exportPath.text exfile = savefilepath +"\\"+ filename FbxExporterSetParam"Animation" false FbxExporterSetParam "BakeAnimation"false Exportfile exfile #noPrompt using:exporterPlugin.classes[8] i.isHidden =true ) shellLaunch savefilepath"" ) ) ) resetMaxFile #noPrompt ) if body.state ==true and body_int ==0 then messagebox"无身体文件可导出" if head.state ==true and head_int ==0 then messagebox"无头部文件可导出" if face.state ==true and face_int ==0 then messagebox"无脸部文件可导出" if NPC.state ==true and NPC_int ==0 then messagebox"无NPC文件可导出" ) on body changed state do ( head.state = false NPC.state = false face.state =false ) on head changed state do ( body.state = false NPC.state = false face.state = false ) on NPC changed state do ( body.state = false head.state = false face.state = false ) on face changed state do ( body.state = false head.state = false NPC.state = false ) on ExportAni pressed do ( if importPath.text.count != 0 and exportPath.text.count!=0 then ( body_int =0 importFiles = getFiles(importPath.text+"\\*"+".max") savefilepath = () for f in importFiles do ( loadMaxFile f quiet:true arrayExportbody = #() for i in $*body do ( if (i.isHidden == false) then append arrayExportbody i --将以body结尾的所有物体加入数组 ) if arrayExportbody.count != 0 then ( body_int+=1 for i in geometry do i.isHidden = true --隐藏所有的物体 for i in arrayExportbody do ( i.isHidden =false -- 先将第一个身体显示,此时应该只有第一个身体还有骨骼 没其他任何物件 max select all filename = getFilenameFile f savefilepath = exportPath.text exfile = savefilepath +"\\"+ filename FbxExporterSetParam"Animation" true FbxExporterSetParam "BakeAnimation"true Exportfile exfile #noPrompt using:exporterPlugin.classes[8] i.isHidden =true ) shellLaunch savefilepath"" ) ) ) ) ) createdialog export )