【MAXscript】3ds max bip批量转fbx

工作需要,在同事的帮助下写了一段代码用于批量转换bip文件。之前在网上查了很久都没找到相应的教程或者代码,把自己的代码发上来帮助有需要的人。

-- https://cganimator.com/uiaccessor-mini-tutorial-how-to-control-make-preview-dialog/

-- 获取bip动画的长度,控制fbx导出时候的长度
fn getLastKeyTime bipCtl = (
	-- get subAnim controllers
	-- maybe only three subAnim controller, i don't know
	vertical_subAnim = bipCtl.vertical
	horizontal_subAnim = bipCtl.horizontal
	turning_subAnim = bipCtl.turning
	
	last_key_index = vertical_subAnim.keys.count
	if last_key_index != 0 then
	(
		key = vertical_subAnim.keys[last_key_index]
	)
	if horizontal_subAnim.keys.count > last_key_index then(
		last_key_index = horizontal_subAnim.keys.count
		key = horizontal_subAnim.keys[last_key_index]
	)
	if turning_subAnim.keys.count > last_key_index then(
		last_key_index = turning_subAnim.keys.count
		key = turning_subAnim.keys[last_key_index]
	)
	if last_key_index <=1 then(
		return 1f
	)
	return key.time
)

-- 转换
fn batchConvertBipToFBX bipCtl srcDir dstDir = (

    --file_list = getFiles(srcDir + "\\*.bip")
	file_list = getFiles (srcDir + "\\*.bip") recurse:true
	--file_list = getFiles (srcDir + "\\*.bip") recurse:false

    for file in file_list do
    (
		
		-- load bip file
		try
			biped.loadBipFile bipCtl file
		catch
		(
			print "?????????:" + file
			continue
		)
		
		
		--file_length = biped.getl
		FBXExporterSetParam "Animation" true
		FBXExporterSetParam "BakeAnimation" true
		FBXExporterSetParam "BakeFrameStart" 0
		
		last_key_time = getLastKeyTime bipCtl
		animationRange = interval 0f last_key_time
		print last_key_time.frame
		FBXExporterSetParam "BakeFrameEnd" (last_key_time.frame as integer)
		FBXExporterSetParam "BakeResampleAnimation"	true
		FBXExporterSetParam "UpAxis" "Y"
        
		srcDir_list = GetDirectories (srcDir + "\\*")
		if srcDir_list.count >= 1 then
		(
			file_dir_array = filterString (getFilenamePath file) "\\"
			local output_path = (dstDir + "\\" +file_dir_array[file_dir_array.count] + "-" + getFilenameFile file + ".fbx")
		)
		else
		(
			local output_path = (dstDir + "\\" + getFilenameFile file + ".fbx")
		)
		exportFile output_path #noPrompt selectedOnly:false using:FBXEXP
		
		print ("convert '" + file + "' to '" + output_path + "'")
		
        
    )
)

-- 导入时可能会弹出帧率转换确认对话框,这个函数用来处理该对话框
fn frameRateChangeHook = (
    local WindowHandle = DialogMonitorOPS.GetWindowHandle()
    local WindowTitle = (UIAccessor.GetWindowText WindowHandle)

    if WindowTitle == "Frame Rate Change" then (
        -- print "'Frame Rate Change' dialog is detected"
        
		-- Get the handles of all controls in the dialog
		local dialogChildren = (windows.getChildrenHWND WindowHandle)
		
		-- print (dialogChildren) -- uncomment this line to see available buttons
		
		UIAccessor.PressButton dialogChildren[3][1] -- choose "quantize"
		-- UIAccessor.PressButton dialogChildren[6][1] -- choose "map frames"
		
		-- click OK
		UIAccessor.PressButtonByName WindowHandle "OK"
    )
    True
)



-- start monitoring dialogs and register hook
DialogMonitorOPS.enabled = true
DialogMonitorOPS.RegisterNotification frameRateChangeHook id:#frameRateChangeHook
pluginManager.loadClass FbxExporter

-- the real convert job
-- 这里写源目录
srcDir = "C:\\Users\\XPS\\Downloads\\Motion\\"
-- 这里写目标目录
dstDir = "C:\\Users\\XPS\\Downloads\\Motion\\result\\"

-- 用于加载bip文件的biped骨骼名字
bip = $Bip001
bip_ctl = bip.transform.controller


batchConvertBipToFBX bip_ctl srcDir dstDir

-- stop monitoring dialogs and unregister hook
DialogMonitorOPS.unRegisterNotification id:#frameRateChangeHook
DialogMonitorOPS.enabled = false


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值