max各种相机导出到ue4匹配镜头的工具集

news2024/11/15 11:58:53

总览

 rollout export_UE4Cam_v2 "导出UE4Cam_v2:半自动" width:200 height:120
 (
	HyperLink  explain "在打开的max文件中使用" pos:[25,12] width:200 height:15 color:(color 255 155 0)	 
	GroupBox grp1 "要导出的相机名" pos:[5,28] width:179 height:40
	pickbutton OutCam "拾取相机" pos:[20,40] width:150 height:20
	GroupBox grp2 "要导出的fbx文件名" pos:[5,70] width:179 height:50
	button	 bt_create	"Create UE4 Camera" pos:[20,85] width:150 height:32 enabled:true
	 
-----逐行写入文本------------
fn format_txt FilePath filetext1 filetext2=
(	
	if doesFileExist FilePath == true
		then
	(
		fin = openfile FilePath mode:"r+"
		seek fin #eof
		txt = filetext1+RenderWidth as string+"\n"+filetext2+RenderHeight as string+"\n"
		format txt to:fin
		close fin
	)
	else
	(
		newfile = createFile FilePath writeBOM:true
		close newfile
		format_txt FilePath filetext1 filetext2
		)
)
-----end逐行写入文本-----------------

    on OutCam picked obj do
    (
     OutCam.text = obj.name
        )
 
 	on bt_create pressed do
 	(		
		Freecamera fov:45 targetDistance:314.512 nearclip:1 farclip:1000 nearrange:0 farrange:1000 mpassEnabled:off mpassRenderPerPass:off pos:[0,0,0] isSelected:on
		mycam = OutCam.text
		$.name = mycam
		UE4CAM =$
		MAXCAM =getnodebyname mycam
		UE4CAM.Position=MAXCAM.position
		UE4CAM.FOV=MAXCAM.FOV
		--位置约束
		UE4CAM.Position.controller= Position_Constraint ()
		A = UE4CAM.Position.controller
		A.appendTarget MAXCAM 100
		--方向约束
		UE4CAM.rotation.controller= Orientation_Constraint ()
		B = UE4CAM.rotation.controller
		
		B.appendTarget MAXCAM 100

		--开始塌陷
				local forceUpdate = keyboard.shiftPressed -- if SHIFT is pressed when the macro is called, a viewport redraw is enforced for each timestep to ensure a full update of all controllers
				if forceUpdate then format "MB Collapse: Enforcing full viewport update. This might be slow but will ensure proper updating of all controllers\n"
				
					local p = undefined
					local old_prs_ctrl = copy UE4CAM.transform.controller		-- store old controller for catch()
					with undo on (
						if not forceUpdate then disableSceneRedraw();	-- not using redraw context for max4 compatibility
						-- disableSceneRedraw is problematic as not all scripted controllers are updated!
						try (
							p = Point()			-- create temp point object
							-- copy global transform of source object into temp object
							for i = animationRange.start to animationRange.end do (
								if forceUpdate then sliderTime = i	-- set slider time to force a global update of all animation data
								at time i (
									with animate on p.transform = UE4CAM.transform
								)
							)
							-- kill old transform controller and assign new, clean one
							UE4CAM.transform.controller = transform_script()	
							UE4CAM.transform.controller = prs()	
							
							if not (isGroupMember UE4CAM) then UE4CAM.parent = undefined	-- unlink if not in a group
							-- copy temp object animation back into source object
							for i = animationRange.start to animationRange.end do (
								at time i (
									with animate on	UE4CAM.transform = p.transform
								)
							)

							delete p			-- delete temp point obj
							p = undefined
							if not forceUpdate then enableSceneRedraw()
						)--try
					catch(
						format "coder zsz:QQ  : Fatal error - exiting\n"
									if p!=undefined then delete p
									UE4CAM.transform.controller = old_prs_ctrl
									if not forceUpdate then enableSceneRedraw()
						  )-- catch				
					)--with undo
		--塌陷结束
					
		-----导出fbx文件----
        -- 使用一个.net文件windows窗口—导出fbx文件
		browse_dialog = dotNetObject "System.Windows.Forms.SaveFileDialog" --建立一个打开文件对话框
		DotNetFile = DotNetClass "System.IO.File"--创建.net文件
		browse_dialog.title = "保存文件" --设置标题
		browse_dialog.Filter = "fbx Files (*.fbx)|*.fbx|All Files (*.*)|*.*" --确认这个文件过滤
		browse_dialog.fileName = trimright maxfilename ".max"
		browse_dialog.FilterIndex = 2 --设置文件过滤下拉菜单长度
		result = browse_dialog.showDialog() --显示对话框,得到的结果进变量
		if (result.Equals result.OK) then
		(
			if ( not (DotNetFile.Exists browse_dialog.FileName)) then
			(
				select UE4CAM
				if selection.count !=0 then(	
				AA=browse_dialog.fileName+".fbx"
				exportFile AA  #noPrompt selectedOnly:true using:fbxexp
				BB=browse_dialog.fileName+".TXT"
				format_txt BB "renderWidth=" "renderHight="
				)
			)

		)			
		--删除相机 	
		delete UE4CAM
        free(filepath)					
	)
	
 )
 rollout exportFBX "导出fbx模:半自动" width:200 height:100
 (
	HyperLink explain "在打开的max文件中使用" pos:[25,0] width:200 height:15 color:(color 255 155 0)	 
	GroupBox grp1 "要导出的角色根骨骼" pos:[5,15] width:179 height:80
	pickbutton PickRoot "拾取根骨骼" pos:[20,30] width:150 height:20
	button	 bt_OutFBX	"输出fbx模型" pos:[20,55] width:150 height:30 enabled:true

	 on PickRoot picked obj do
 	( 
		PickRoot.text = obj.name
	)		
	 on bt_OutFBX pressed do
 	( 
		ChrBone=getnodebyname PickRoot.text
		select ChrBone
		--根据根选择此层级所有物体
		if selection.count !=0 then(
			fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
			  
			  select (getTheChildren includeParent:true)
			  select (getTheChildren())
			  
			  getTheChildren includeParent:true as array
			  getTheChildren() as array
		  )
		mysel=selection as array 
		-----对齐帧处理-----
					debb = 10000
					finn=-10000 
						for a in selection do
					(
						if  (classof a == BoneGeometry) then(
							if (numKeys a.position.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.position.controller
								starttime = getkeytime a.position.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.position.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
						if (classof a == Biped_Object) then(
							if (numKeys a.transform.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.transform.controller
								starttime = getkeytime a.transform.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.transform.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
					)
					animationRange = interval debb finn	
	-----end对齐帧处理-----
					
	------------查找蒙皮中具有bip字样的模型并一起选择---------------
		if selection.count !=0 then(
			actionMan.executeAction 0 "283"  -- Tools: Unfreeze All
			max unfreeze all	  
			allTheSkin = for obj in objects where (classof obj==PolyMeshObject)  collect obj
			for f in allTheSkin do(
			skinMods = getclassinstances Skin target:f 
			max modify mode
			modPanel.setCurrentObject f.modifiers[#Skin]
			skinOps.getnumberbones skinMods[1]
			bonename =skinOps.getBoneName skinMods[1] 1 0
			bonename =skinOps.getBoneName skinMods[1] 2 0	
			if findString bonename "Bip" ==1 then (join mysel f)else(deselect f)
			selectmore mysel
			)
		)
        -----使用一个.net文件windows窗口—导出fbx文件------
		browse_dialog = dotNetObject "System.Windows.Forms.SaveFileDialog" --建立一个打开文件对话框
		DotNetFile = DotNetClass "System.IO.File"--创建.net文件
		browse_dialog.title = "保存文件" --设置标题
		browse_dialog.Filter = "fbx Files (*.fbx)|*.fbx|All Files (*.*)|*.*" --确认这个文件过滤
		browse_dialog.fileName = trimright maxfilename ".max"
		browse_dialog.FilterIndex = 2 --设置文件过滤下拉菜单长度
		result = browse_dialog.showDialog() --显示对话框,得到的结果进变量
		if (result.Equals result.OK) then
		(
			if ( not (DotNetFile.Exists browse_dialog.FileName)) then
			(
				if selection.count !=0 then(	
				AA=browse_dialog.fileName+"."+"model"+".fbx"
				exportFile AA #noPrompt selectedOnly:true using:fbxexp
				)
			)

		)
	)
 )
 rollout exportFBX_ue4cam_v1 "批出fbx模&UEcam_V1:自动" width:200 height:120
 (
HyperLink explain "指定目录即可,不需要打开文件" pos:[25,0] width:200 height:15  color:(color 255 155 0)
edittext selfile "" pos:[10,20] width:140 height:19 text:"...请选择目录"
button btn_browse "..."  pos:[160,20] width:30 height:19 
checkBox ignore "忽略backup文件" pos:[60,40] width:100 height:19
-- radioButtons rdo1 "" pos:[30,40] width:168 height:16 labels:#("输出相机", "输出模型") default:1 columns:2	 
button	 bt_create	"批量输出fbx" pos:[20,60] width:150 height:32 enabled:true

-------逐行写入文本------------
fn format_txt filepath filetext1 filetext2=
(	
	if doesFileExist filepath == true
		then
	(
		fin = openfile filepath mode:"r+"
		seek fin #eof
		txt = filetext1+RenderWidth as string+"\n"+filetext2+RenderHeight as string+"\n"
		format txt to:fin
		close fin
	)
	else
	(
		newfile = createFile filepath writeBOM:true
		close newfile
		format_txt filepath filetext1 filetext2
		)
)  -- 逐行写入文本	 
	 
	 on btn_browse pressed do
 	( 		
		global DIR = getSavePath caption:"选择max目录"
		if (DIR != undefined) then ( selfile.text = dir )
	)		
	 on bt_create pressed do
 	( 
	 files =DIR+"\*.max"
	OldFiles=getfiles files	
	GetFile= getFiles files	 
	if (ignore.checked) then(
		 ---排除掉backup文件--
		 UndoFiles=getfiles (DIR+"\*backup*.max")
		 for j = 1 to UndoFiles.count do	while (index = (findItem GetFile UndoFiles[j])) != 0 do (deleteItem GetFile index)
		---排除掉backup文件end--	 
	)	
	 Maxfiles=GetFile
		 
	 for f in Maxfiles do (
		--打开max文件--- 
		 loadMaxfile f missingExtFilesAction:#logmsg

		---切割文本内容
		mydir=trimRight f ".max"
		global filename=trimLeft mydir DIR
        global filepath=(DIR+"/"+filename+".txt") as string		 
 		--------start 输出model.fbx-------	
		 
		---------只输出bip模型------------
		--选择所有bip物体
		select $'*bip*' 
			
		mysel= selection as array
		--根据bip选择根
		for f in mysel do(
		fn getRoot node = if isvalidnode node do (while node.parent != undefined do node = node.parent; node)
		aaa=getRoot f
		select aaa
		)
		--根据根选择此层级所有物体
		if (selection.count !=0) then(
			fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
			  
			  select (getTheChildren includeParent:true)
			  select (getTheChildren())
			  
			  getTheChildren includeParent:true as array
			  getTheChildren() as array
		  )

		if (selection.count !=0) do(
		-----对齐帧处理-----
					debb = 10000
					finn=-10000 
						for a in selection do
					(
						if  (classof a == BoneGeometry) then(
							if (numKeys a.position.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.position.controller
								starttime = getkeytime a.position.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.position.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
						else if (classof a == Biped_Object) then(
							if (numKeys a.transform.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.transform.controller
								starttime = getkeytime a.transform.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.transform.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
					)
					animationRange = interval debb finn	

	-----end对齐帧处理-----
				)
				
	------------查找蒙皮中具有bip字样的模型并一起选择---------------
		if selection.count !=0 then(
			actionMan.executeAction 0 "283"  -- Tools: Unfreeze All
			max unfreeze all	  
			allTheSkin = for obj in objects where (classof obj==PolyMeshObject)  collect obj
			for f in allTheSkin do(
			skinMods = getclassinstances Skin target:f 
			max modify mode
			modPanel.setCurrentObject f.modifiers[#Skin]
			skinOps.getnumberbones skinMods[1]
			bonename =skinOps.getBoneName skinMods[1] 1 0
			bonename =skinOps.getBoneName skinMods[1] 2 0	
			if findString bonename "Bip" ==1 then (join mysel f)else(deselect f)
			selectmore mysel
			)
		)
		---------只输出bip模型------------

		if selection.count !=0 then(
        AA=Dir+"/"+filename+"."+"model"+".fbx"	
		exportFile  AA #noPrompt selectedOnly:true using:fbxexp
		deselect $	
		)
		----end 输出model.fbx---
		 
		 --选择相机(包括隐藏的)跳过目标物体
		camsARr = for o in cameras where classof o != targetobject collect o
		select camsARr  filter:FilterCameras showHidden:true
		MaxCamSelSet = selection as array	
		------start输出cam.fbx------
		for i in MaxCamSelSet do(
					MAXCAM= i
	
					Freecamera fov:45 targetDistance:314.512 nearclip:1 farclip:1000 nearrange:0 farrange:1000 mpassEnabled:off mpassRenderPerPass:off pos:[0,0,0] isSelected:on
					hide $
					$.name =FileName+"."+i.name --设置相机名称
					UE4CAM =$
					UE4CAM.Position=MAXCAM.position
					UE4CAM.FOV=MAXCAM.FOV
						
					--位置约束
					UE4CAM.Position.controller= Position_Constraint ()
					A = UE4CAM.Position.controller
					A.appendTarget MAXCAM 100
					--方向约束
					UE4CAM.rotation.controller= Orientation_Constraint ()
					B = UE4CAM.rotation.controller
					
					B.appendTarget MAXCAM 100

		--开始塌陷
				local forceUpdate = keyboard.shiftPressed -- if SHIFT is pressed when the macro is called, a viewport redraw is enforced for each timestep to ensure a full update of all controllers
				if forceUpdate then format "MB Collapse: Enforcing full viewport update. This might be slow but will ensure proper updating of all controllers\n"
				
					local p = undefined
					local old_prs_ctrl = copy UE4CAM.transform.controller		-- store old controller for catch()
					with undo on (
						if not forceUpdate then disableSceneRedraw();	-- not using redraw context for max4 compatibility
						-- disableSceneRedraw is problematic as not all scripted controllers are updated!
						try (
							p = Point()			-- create temp point object
							-- copy global transform of source object into temp object
							for i = animationRange.start to animationRange.end do (
								if forceUpdate then sliderTime = i	-- set slider time to force a global update of all animation data
								at time i (
									with animate on p.transform = UE4CAM.transform
								)
							)
							-- kill old transform controller and assign new, clean one
							UE4CAM.transform.controller = transform_script()	
							UE4CAM.transform.controller = prs()	
							
							if not (isGroupMember UE4CAM) then UE4CAM.parent = undefined	-- unlink if not in a group
							-- copy temp object animation back into source object
							for i = animationRange.start to animationRange.end do (
								at time i (
									with animate on	UE4CAM.transform = p.transform
								)
							)
							delete p			-- delete temp point obj
							p = undefined
							if not forceUpdate then enableSceneRedraw()
						)--try
					catch(
						format "coder zsz:QQ  : Fatal error - exiting\n"
									if p!=undefined then delete p
									UE4CAM.transform.controller = old_prs_ctrl
									if not forceUpdate then enableSceneRedraw()
						  )-- catch				
					)--with undo
		--塌陷结束

					----对齐相机的关键帧到动画范围---

					debb = 10000
					finn=-10000 
					for a in selection do
					(
						if (numKeys a.position.controller > 0)then(
							sortKeys a.controller
							num_keys = numkeys a.position.controller
							starttime = getkeytime a.position.controller 1
							endtime = starttime
							for O = 1 to num_keys do 
							(
						 
								key_time = getkeytime a.position.controller O
								if key_time > endtime then
									 endtime = key_time
							)
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime
						)
						else(
							starttime = 1
							endtime = 100				
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime				
							)
					)
					animationRange = interval debb finn	
					----对齐相机的关键帧到动画范围end---	
					
		--------导出fbx文件-------
						CAM=MAXCAM.name
						BB=DIR+"/"+filename+"."+CAM+".fbx"

					exportFile  BB #noPrompt selectedOnly:true using:fbxexp	
					
				)	
		------end输出cam.fbx------
				
-- 		------输出cam.txt------
		if MaxCamSelSet.count !=0 then(		
		format_txt filepath "renderWidth=" "renderHight="
		)
-- 		------end输出cam.txt------	
			
		 ------重置max场景-------		
		resetMaxFile #noPrompt
		
		)
	----删除导入机制生产的备份文件---
		
	 ---排除掉新产生的backup文件--
	 NewFiles=getfiles (DIR+"\*.max")
	
	 for j = 1 to OldFiles.count do	while (index = (findItem NewFiles OldFiles[j])) != 0 do (deleteItem NewFiles index)
	 WillDelFiles=NewFiles
	---排除掉新产生的backup文件end--
 
	for a in WillDelFiles do
	(			
		deletefile a
		) 
	----删除导入机制生产的备份文件---
		
	----释放全局变量DIR	
 	free(DIR)
	)
 )

 rollout exportFBX_ue4cam_v2 "批出fb模&UEcam_V2:模式自选" width:200 height:100
 (
HyperLink explain "指定目录即可,不需要打开文件" pos:[25,0] width:200 height:15 color:(color 255 155 0)
edittext selfile "" pos:[10,15] width:140 height:19 text:"...请选择目录"
button btn_browse "..."  pos:[160,15] width:30 height:19
checkBox ignore "忽略backup文件" pos:[60,35] width:100 height:19
label explain1 "输出相机是打开模式,输出模型是导入模式" pos:[0,64] width:200 height:15 
radioButtons rdo1 "" pos:[30,50] width:168 height:16 labels:#("输出相机", "输出模型") default:1 columns:2	 
button	 bt_create	"批量输出fbx" pos:[20,80] width:150 height:32 enabled:true

---函数部分--
 fn LoadOrMergeFile f = (
		 if rdo1.state ==1 then (
			loadMaxfile f missingExtFilesAction:#logmsg
		)
		if rdo1.state ==2 then (
			mergeMaxfile f 
		)
 )  

---------逐行写入文本------------
fn format_txt FilePath filetext1 filetext2=
(	
	if doesFileExist FilePath == true
		then
	(
		fin = openfile FilePath mode:"r+"
		seek fin #eof
		txt = filetext1+RenderWidth as string+"\n"+filetext2+RenderHeight as string+"\n"
		format txt to:fin
		close fin
	)
	else
	(
		newfile = createFile FilePath writeBOM:true
		close newfile
		format_txt FilePath filetext1 filetext2
		)
)
-- 逐行写入文本
			
---///end函数部分--
	 on btn_browse pressed do
 	( 
		global DIR = getSavePath caption:"选择max目录"
		if (DIR != undefined) do ( selfile.text = DIR )	
	)	
	
	 on bt_create pressed do
 	( 
	 files =DIR+"/"+"*.max"
	 OldFiles=getfiles files	
	 GetFile= getFiles files
    if (ignore.checked)then(		
 	 ---排除掉backup文件--
	 WillDelFiles=getfiles (DIR+"\*backup*.max")
	 for j = 1 to WillDelFiles.count do	while (index = (findItem GetFile WillDelFiles[j])) != 0 do (deleteItem GetFile index)
	---排除掉backup文件end-- 
	)
	
	Maxfiles=GetFile 
		 
	 for f in Maxfiles do (
			---切割文本内容
			mydir=trimRight f ".max"
			global FileName=trimLeft mydir DIR
			global FilePath=(DIR+"/"+FileName+".txt") as string	
			--导入max文件--- 
			LoadOrMergeFile f	 
			----输出model.fbx ---		 
	-- 		ExportModel,见 rdo1的写在那里面
			 if rdo1.state ==1 then (
		---选择相机(包括隐藏的)跳过目标物体
		camsArr = for o in cameras where classof o != targetobject collect o
		select camsArr  filter:FilterCameras showHidden:true
		MaxCamSelSet = selection as array	
		------start输出cam.fbx------
		for i in MaxCamSelSet do(
					MAXCAM= i
			
					Freecamera fov:45 targetDistance:314.512 nearclip:1 farclip:1000 nearrange:0 farrange:1000 mpassEnabled:off mpassRenderPerPass:off pos:[0,0,0] isSelected:on
					hide $
					$.name =FileName+"."+i.name --设置相机名称
					UE4CAM =$
					UE4CAM.Position=MAXCAM.position
					UE4CAM.FOV=MAXCAM.FOV
						
					--位置约束
					UE4CAM.Position.controller= Position_Constraint ()
					A = UE4CAM.Position.controller
					A.appendTarget MAXCAM 100
					--方向约束
					UE4CAM.rotation.controller= Orientation_Constraint ()
					B = UE4CAM.rotation.controller
					
					B.appendTarget MAXCAM 100

		--开始塌陷
				local forceUpdate = keyboard.shiftPressed -- if SHIFT is pressed when the macro is called, a viewport redraw is enforced for each timestep to ensure a full update of all controllers
				if forceUpdate then format "MB Collapse: Enforcing full viewport update. This might be slow but will ensure proper updating of all controllers\n"
				
					local p = undefined
					local old_prs_ctrl = copy UE4CAM.transform.controller		-- store old controller for catch()
					with undo on (
						if not forceUpdate then disableSceneRedraw();	-- not using redraw context for max4 compatibility
						-- disableSceneRedraw is problematic as not all scripted controllers are updated!
						try (
							p = Point()								-- create temp point object
							
							-- copy global transform of source object into temp object
							for i = animationRange.start to animationRange.end do (
								if forceUpdate then sliderTime = i	-- set slider time to force a global update of all animation data
								at time i (
									with animate on p.transform = UE4CAM.transform
								)
							)
							-- kill old transform controller and assign new, clean one
							UE4CAM.transform.controller = transform_script()	
							UE4CAM.transform.controller = prs()	
							
							if not (isGroupMember UE4CAM) then UE4CAM.parent = undefined	-- unlink if not in a group
							-- copy temp object animation back into source object
							for i = animationRange.start to animationRange.end do (
								at time i (
									with animate on	UE4CAM.transform = p.transform
								)
							)
							delete p			-- delete temp point obj
							p = undefined
							if not forceUpdate then enableSceneRedraw()
						)--try
					catch(
						format "coder zsz:QQ  : Fatal error - exiting\n"
									if p!=undefined then delete p
									UE4CAM.transform.controller = old_prs_ctrl
									if not forceUpdate then enableSceneRedraw()
						  )-- catch				
					)--with undo
		--塌陷结束
					
					----对齐相机的关键帧到动画范围---
					debb = 10000
					finn=-10000 
					for a in selection do
					(
						if (numKeys a.position.controller > 0)then(
							sortKeys a.controller
							num_keys = numkeys a.position.controller
							starttime = getkeytime a.position.controller 1
							endtime = starttime
							for O = 1 to num_keys do 
							(
						 
								key_time = getkeytime a.position.controller O
								if key_time > endtime then
									 endtime = key_time
							)
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime
						)
						else(
							starttime = 1
							endtime = 100				
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime				
							)
					)
					animationRange = interval debb finn	
					----对齐相机的关键帧到动画范围end---	
					
		--------导出fbx文件-------
					CAM=MAXCAM.name
					FBXFileName=DIR+"/"+FileName+"."+CAM+".fbx"
					exportFile FBXFileName #noPrompt selectedOnly:true using:fbxexpp	
				)	
		------end输出cam.fbx------
				 
				------输出cam.txt------
				if MaxCamSelSet.count !=0 then(				
				format_txt FilePath "renderWidth=" "renderHight="
				)
				------end输出cam.txt------
				 
			)
			if rdo1.state ==2 then (

		---------只输出bip模型------------
		--选择所有bip物体
		select $'*bip*' 
		
		mysel= selection as array
		--根据bip选择根
		for f in mysel do(
		fn getRoot node = if isvalidnode node do (while node.parent != undefined do node = node.parent; node)
		aaa=getRoot f
		select aaa
		)
		--根据根选择此层级所有物体
		if selection.count !=0 then(
		fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
		  
		  select (getTheChildren includeParent:true)
		  select (getTheChildren())
		  
		  getTheChildren includeParent:true as array
		  getTheChildren() as array
		)
		-----对齐帧处理-----
					debb = 10000
					finn=-10000 
						for a in selection do
					(
						if  (classof a == BoneGeometry) then(
							if (numKeys a.position.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.position.controller
								starttime = getkeytime a.position.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.position.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
						if (classof a == Biped_Object) then(
							if (numKeys a.transform.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.transform.controller
								starttime = getkeytime a.transform.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.transform.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
					)
					animationRange = interval debb finn	
	-----end对齐帧处理-----
					
	------------查找蒙皮中具有bip字样的模型并一起选择---------------
		if selection.count !=0 then(		  
			actionMan.executeAction 0 "283"  -- Tools: Unfreeze All
			max unfreeze all
			allTheSkin = for obj in objects where (classof obj==PolyMeshObject)  collect obj
			for f in allTheSkin do(
			skinMods = getclassinstances Skin target:f 
			max modify mode
			modPanel.setCurrentObject f.modifiers[#Skin]
			skinOps.getnumberbones skinMods[1]
			bonename =skinOps.getBoneName skinMods[1] 1 0
			bonename =skinOps.getBoneName skinMods[1] 2 0	
			if findString bonename "Bip" ==1 then (join mysel f)else(deselect f)
			selectmore mysel
			)
		)
		---------只输出bip模型------------
	
				----start 输出model.fbx---	
				if selection.count !=0 then(		
				AA=Dir+"/"+FileName+"."+"model"+".fbx"	
				exportFile  AA #noPrompt selectedOnly:true using:fbxexp
				)
				----end 输出model.fbx---
			) 
			
			 ------重置max场景-------
			resetMaxFile #noPrompt	
		)
	----删除导入机制生产的备份文件---
		
	 ---排除掉新产生的backup文件--
	 NewFiles=getfiles (DIR+"\*.max")
	
	 for j = 1 to OldFiles.count do	while (index = (findItem NewFiles OldFiles[j])) != 0 do (deleteItem NewFiles index)
	 WillDelFiles=NewFiles
	---排除掉新产生的backup文件end--
 
	for a in WillDelFiles do
	(			
		deletefile a
		) 
	----删除导入机制生产的备份文件---
		
	----释放全局变量DIR	
 	free(DIR)
	)
 )

-------------------------------------------------------------	
globalrollout = newrolloutfloater "导ue4模型和相机工具集" 200 535
addRollout export_UE4Cam_v2 globalrollout
addRollout exportFBX globalrollout
addRollout exportFBX_ue4cam_v1 globalrollout
addRollout exportFBX_ue4cam_v2 globalrollout 
-------------------------------------------------------------------------

------分部件代码展示:-----

 rollout export_UE4Cam_v2 "导出UE4Cam_v2:半自动" width:200 height:120
 (
	HyperLink  explain "在打开的max文件中使用" pos:[25,12] width:200 height:15 color:(color 255 155 0)	 
	GroupBox grp1 "要导出的相机名" pos:[5,28] width:179 height:40
	pickbutton OutCam "拾取相机" pos:[20,40] width:150 height:20
	GroupBox grp2 "要导出的fbx文件名" pos:[5,70] width:179 height:50
	button	 bt_create	"Create UE4 Camera" pos:[20,85] width:150 height:32 enabled:true
	 
-----逐行写入文本------------
fn format_txt FilePath filetext1 filetext2=
(	
	if doesFileExist FilePath == true
		then
	(
		fin = openfile FilePath mode:"r+"
		seek fin #eof
		txt = filetext1+RenderWidth as string+"\n"+filetext2+RenderHeight as string+"\n"
		format txt to:fin
		close fin
	)
	else
	(
		newfile = createFile FilePath writeBOM:true
		close newfile
		format_txt FilePath filetext1 filetext2
		)
)
-----end逐行写入文本-----------------

    on OutCam picked obj do
    (
     OutCam.text = obj.name
        )
 
 	on bt_create pressed do
 	(		
		Freecamera fov:45 targetDistance:314.512 nearclip:1 farclip:1000 nearrange:0 farrange:1000 mpassEnabled:off mpassRenderPerPass:off pos:[0,0,0] isSelected:on
		mycam = OutCam.text
		$.name = mycam
		UE4CAM =$
		MAXCAM =getnodebyname mycam
		UE4CAM.Position=MAXCAM.position
		UE4CAM.FOV=MAXCAM.FOV
		--位置约束
		UE4CAM.Position.controller= Position_Constraint ()
		A = UE4CAM.Position.controller
		A.appendTarget MAXCAM 100
		--方向约束
		UE4CAM.rotation.controller= Orientation_Constraint ()
		B = UE4CAM.rotation.controller
		
		B.appendTarget MAXCAM 100

		--开始塌陷
				local forceUpdate = keyboard.shiftPressed -- if SHIFT is pressed when the macro is called, a viewport redraw is enforced for each timestep to ensure a full update of all controllers
				if forceUpdate then format "MB Collapse: Enforcing full viewport update. This might be slow but will ensure proper updating of all controllers\n"
				
					local p = undefined
					local old_prs_ctrl = copy UE4CAM.transform.controller		-- store old controller for catch()
					with undo on (
						if not forceUpdate then disableSceneRedraw();	-- not using redraw context for max4 compatibility
						-- disableSceneRedraw is problematic as not all scripted controllers are updated!
						try (
							p = Point()			-- create temp point object
							-- copy global transform of source object into temp object
							for i = animationRange.start to animationRange.end do (
								if forceUpdate then sliderTime = i	-- set slider time to force a global update of all animation data
								at time i (
									with animate on p.transform = UE4CAM.transform
								)
							)
							-- kill old transform controller and assign new, clean one
							UE4CAM.transform.controller = transform_script()	
							UE4CAM.transform.controller = prs()	
							
							if not (isGroupMember UE4CAM) then UE4CAM.parent = undefined	-- unlink if not in a group
							-- copy temp object animation back into source object
							for i = animationRange.start to animationRange.end do (
								at time i (
									with animate on	UE4CAM.transform = p.transform
								)
							)

							delete p			-- delete temp point obj
							p = undefined
							if not forceUpdate then enableSceneRedraw()
						)--try
					catch(
						format "coder zsz:QQ  : Fatal error - exiting\n"
									if p!=undefined then delete p
									UE4CAM.transform.controller = old_prs_ctrl
									if not forceUpdate then enableSceneRedraw()
						  )-- catch				
					)--with undo
		--塌陷结束
					
		-----导出fbx文件----
        -- 使用一个.net文件windows窗口—导出fbx文件
		browse_dialog = dotNetObject "System.Windows.Forms.SaveFileDialog" --建立一个打开文件对话框
		DotNetFile = DotNetClass "System.IO.File"--创建.net文件
		browse_dialog.title = "保存文件" --设置标题
		browse_dialog.Filter = "fbx Files (*.fbx)|*.fbx|All Files (*.*)|*.*" --确认这个文件过滤
		browse_dialog.fileName = trimright maxfilename ".max"
		browse_dialog.FilterIndex = 2 --设置文件过滤下拉菜单长度
		result = browse_dialog.showDialog() --显示对话框,得到的结果进变量
		if (result.Equals result.OK) then
		(
			if ( not (DotNetFile.Exists browse_dialog.FileName)) then
			(
				select UE4CAM
				if selection.count !=0 then(	
				AA=browse_dialog.fileName+".fbx"
				exportFile AA  #noPrompt selectedOnly:true using:fbxexp
				BB=browse_dialog.fileName+".TXT"
				format_txt BB "renderWidth=" "renderHight="
				)
			)

		)			
		--删除相机 	
		delete UE4CAM
        free(filepath)					
	)
	
 )

rollout exportFBX "导出fbx模:半自动" width:200 height:100
 (
	HyperLink explain "在打开的max文件中使用" pos:[25,0] width:200 height:15 color:(color 255 155 0)	 
	GroupBox grp1 "要导出的角色根骨骼" pos:[5,15] width:179 height:80
	pickbutton PickRoot "拾取根骨骼" pos:[20,30] width:150 height:20
	button	 bt_OutFBX	"输出fbx模型" pos:[20,55] width:150 height:30 enabled:true

	 on PickRoot picked obj do
 	( 
		PickRoot.text = obj.name
	)		
	 on bt_OutFBX pressed do
 	( 
		ChrBone=getnodebyname PickRoot.text
		select ChrBone
		--根据根选择此层级所有物体
		if selection.count !=0 then(
			fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
			  
			  select (getTheChildren includeParent:true)
			  select (getTheChildren())
			  
			  getTheChildren includeParent:true as array
			  getTheChildren() as array
		  )
		mysel=selection as array 
		-----对齐帧处理-----
					debb = 10000
					finn=-10000 
						for a in selection do
					(
						if  (classof a == BoneGeometry) then(
							if (numKeys a.position.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.position.controller
								starttime = getkeytime a.position.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.position.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
						if (classof a == Biped_Object) then(
							if (numKeys a.transform.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.transform.controller
								starttime = getkeytime a.transform.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.transform.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
					)
					animationRange = interval debb finn	
	-----end对齐帧处理-----
					
	------------查找蒙皮中具有bip字样的模型并一起选择---------------
		if selection.count !=0 then(
			actionMan.executeAction 0 "283"  -- Tools: Unfreeze All
			max unfreeze all	  
			allTheSkin = for obj in objects where (classof obj==PolyMeshObject)  collect obj
			for f in allTheSkin do(
			skinMods = getclassinstances Skin target:f 
			max modify mode
			modPanel.setCurrentObject f.modifiers[#Skin]
			skinOps.getnumberbones skinMods[1]
			bonename =skinOps.getBoneName skinMods[1] 1 0
			bonename =skinOps.getBoneName skinMods[1] 2 0	
			if findString bonename "Bip" ==1 then (join mysel f)else(deselect f)
			selectmore mysel
			)
		)
        -----使用一个.net文件windows窗口—导出fbx文件------
		browse_dialog = dotNetObject "System.Windows.Forms.SaveFileDialog" --建立一个打开文件对话框
		DotNetFile = DotNetClass "System.IO.File"--创建.net文件
		browse_dialog.title = "保存文件" --设置标题
		browse_dialog.Filter = "fbx Files (*.fbx)|*.fbx|All Files (*.*)|*.*" --确认这个文件过滤
		browse_dialog.fileName = trimright maxfilename ".max"
		browse_dialog.FilterIndex = 2 --设置文件过滤下拉菜单长度
		result = browse_dialog.showDialog() --显示对话框,得到的结果进变量
		if (result.Equals result.OK) then
		(
			if ( not (DotNetFile.Exists browse_dialog.FileName)) then
			(
				if selection.count !=0 then(	
				AA=browse_dialog.fileName+"."+"model"+".fbx"
				exportFile AA #noPrompt selectedOnly:true using:fbxexp
				)
			)

		)
	)
 )

 rollout exportFBX_ue4cam_v1 "批出fbx模&UEcam_V1:自动" width:200 height:120
 (
HyperLink explain "指定目录即可,不需要打开文件" pos:[25,0] width:200 height:15  color:(color 255 155 0)
edittext selfile "" pos:[10,20] width:140 height:19 text:"...请选择目录"
button btn_browse "..."  pos:[160,20] width:30 height:19 
checkBox ignore "忽略backup文件" pos:[60,40] width:100 height:19
-- radioButtons rdo1 "" pos:[30,40] width:168 height:16 labels:#("输出相机", "输出模型") default:1 columns:2	 
button	 bt_create	"批量输出fbx" pos:[20,60] width:150 height:32 enabled:true

-------逐行写入文本------------
fn format_txt filepath filetext1 filetext2=
(	
	if doesFileExist filepath == true
		then
	(
		fin = openfile filepath mode:"r+"
		seek fin #eof
		txt = filetext1+RenderWidth as string+"\n"+filetext2+RenderHeight as string+"\n"
		format txt to:fin
		close fin
	)
	else
	(
		newfile = createFile filepath writeBOM:true
		close newfile
		format_txt filepath filetext1 filetext2
		)
)  -- 逐行写入文本	 
	 
	 on btn_browse pressed do
 	( 		
		global DIR = getSavePath caption:"选择max目录"
		if (DIR != undefined) then ( selfile.text = dir )
	)		
	 on bt_create pressed do
 	( 
	 files =DIR+"\*.max"
	OldFiles=getfiles files	
	GetFile= getFiles files	 
	if (ignore.checked) then(
		 ---排除掉backup文件--
		 UndoFiles=getfiles (DIR+"\*backup*.max")
		 for j = 1 to UndoFiles.count do	while (index = (findItem GetFile UndoFiles[j])) != 0 do (deleteItem GetFile index)
		---排除掉backup文件end--	 
	)	
	 Maxfiles=GetFile
		 
	 for f in Maxfiles do (
		--打开max文件--- 
		 loadMaxfile f missingExtFilesAction:#logmsg

		---切割文本内容
		mydir=trimRight f ".max"
		global filename=trimLeft mydir DIR
        global filepath=(DIR+"/"+filename+".txt") as string		 
 		--------start 输出model.fbx-------	
		 
		---------只输出bip模型------------
		--选择所有bip物体
		select $'*bip*' 
			
		mysel= selection as array
		--根据bip选择根
		for f in mysel do(
		fn getRoot node = if isvalidnode node do (while node.parent != undefined do node = node.parent; node)
		aaa=getRoot f
		select aaa
		)
		--根据根选择此层级所有物体
		if (selection.count !=0) then(
			fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
			  
			  select (getTheChildren includeParent:true)
			  select (getTheChildren())
			  
			  getTheChildren includeParent:true as array
			  getTheChildren() as array
		  )

		if (selection.count !=0) do(
		-----对齐帧处理-----
					debb = 10000
					finn=-10000 
						for a in selection do
					(
						if  (classof a == BoneGeometry) then(
							if (numKeys a.position.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.position.controller
								starttime = getkeytime a.position.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.position.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
						else if (classof a == Biped_Object) then(
							if (numKeys a.transform.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.transform.controller
								starttime = getkeytime a.transform.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.transform.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
					)
					animationRange = interval debb finn	

	-----end对齐帧处理-----
				)
				
	------------查找蒙皮中具有bip字样的模型并一起选择---------------
		if selection.count !=0 then(
			actionMan.executeAction 0 "283"  -- Tools: Unfreeze All
			max unfreeze all	  
			allTheSkin = for obj in objects where (classof obj==PolyMeshObject)  collect obj
			for f in allTheSkin do(
			skinMods = getclassinstances Skin target:f 
			max modify mode
			modPanel.setCurrentObject f.modifiers[#Skin]
			skinOps.getnumberbones skinMods[1]
			bonename =skinOps.getBoneName skinMods[1] 1 0
			bonename =skinOps.getBoneName skinMods[1] 2 0	
			if findString bonename "Bip" ==1 then (join mysel f)else(deselect f)
			selectmore mysel
			)
		)
		---------只输出bip模型------------

		if selection.count !=0 then(
        AA=Dir+"/"+filename+"."+"model"+".fbx"	
		exportFile  AA #noPrompt selectedOnly:true using:fbxexp
		deselect $	
		)
		----end 输出model.fbx---
		 
		 --选择相机(包括隐藏的)跳过目标物体
		camsARr = for o in cameras where classof o != targetobject collect o
		select camsARr  filter:FilterCameras showHidden:true
		MaxCamSelSet = selection as array	
		------start输出cam.fbx------
		for i in MaxCamSelSet do(
					MAXCAM= i
	
					Freecamera fov:45 targetDistance:314.512 nearclip:1 farclip:1000 nearrange:0 farrange:1000 mpassEnabled:off mpassRenderPerPass:off pos:[0,0,0] isSelected:on
					hide $
					$.name =FileName+"."+i.name --设置相机名称
					UE4CAM =$
					UE4CAM.Position=MAXCAM.position
					UE4CAM.FOV=MAXCAM.FOV
						
					--位置约束
					UE4CAM.Position.controller= Position_Constraint ()
					A = UE4CAM.Position.controller
					A.appendTarget MAXCAM 100
					--方向约束
					UE4CAM.rotation.controller= Orientation_Constraint ()
					B = UE4CAM.rotation.controller
					
					B.appendTarget MAXCAM 100

		--开始塌陷
				local forceUpdate = keyboard.shiftPressed -- if SHIFT is pressed when the macro is called, a viewport redraw is enforced for each timestep to ensure a full update of all controllers
				if forceUpdate then format "MB Collapse: Enforcing full viewport update. This might be slow but will ensure proper updating of all controllers\n"
				
					local p = undefined
					local old_prs_ctrl = copy UE4CAM.transform.controller		-- store old controller for catch()
					with undo on (
						if not forceUpdate then disableSceneRedraw();	-- not using redraw context for max4 compatibility
						-- disableSceneRedraw is problematic as not all scripted controllers are updated!
						try (
							p = Point()			-- create temp point object
							-- copy global transform of source object into temp object
							for i = animationRange.start to animationRange.end do (
								if forceUpdate then sliderTime = i	-- set slider time to force a global update of all animation data
								at time i (
									with animate on p.transform = UE4CAM.transform
								)
							)
							-- kill old transform controller and assign new, clean one
							UE4CAM.transform.controller = transform_script()	
							UE4CAM.transform.controller = prs()	
							
							if not (isGroupMember UE4CAM) then UE4CAM.parent = undefined	-- unlink if not in a group
							-- copy temp object animation back into source object
							for i = animationRange.start to animationRange.end do (
								at time i (
									with animate on	UE4CAM.transform = p.transform
								)
							)
							delete p			-- delete temp point obj
							p = undefined
							if not forceUpdate then enableSceneRedraw()
						)--try
					catch(
						format "coder zsz:QQ  : Fatal error - exiting\n"
									if p!=undefined then delete p
									UE4CAM.transform.controller = old_prs_ctrl
									if not forceUpdate then enableSceneRedraw()
						  )-- catch				
					)--with undo
		--塌陷结束

					----对齐相机的关键帧到动画范围---

					debb = 10000
					finn=-10000 
					for a in selection do
					(
						if (numKeys a.position.controller > 0)then(
							sortKeys a.controller
							num_keys = numkeys a.position.controller
							starttime = getkeytime a.position.controller 1
							endtime = starttime
							for O = 1 to num_keys do 
							(
						 
								key_time = getkeytime a.position.controller O
								if key_time > endtime then
									 endtime = key_time
							)
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime
						)
						else(
							starttime = 1
							endtime = 100				
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime				
							)
					)
					animationRange = interval debb finn	
					----对齐相机的关键帧到动画范围end---	
					
		--------导出fbx文件-------
						CAM=MAXCAM.name
						BB=DIR+"/"+filename+"."+CAM+".fbx"

					exportFile  BB #noPrompt selectedOnly:true using:fbxexp	
					
				)	
		------end输出cam.fbx------
				
-- 		------输出cam.txt------
		if MaxCamSelSet.count !=0 then(		
		format_txt filepath "renderWidth=" "renderHight="
		)
-- 		------end输出cam.txt------	
			
		 ------重置max场景-------		
		resetMaxFile #noPrompt
		
		)
	----删除导入机制生产的备份文件---
		
	 ---排除掉新产生的backup文件--
	 NewFiles=getfiles (DIR+"\*.max")
	
	 for j = 1 to OldFiles.count do	while (index = (findItem NewFiles OldFiles[j])) != 0 do (deleteItem NewFiles index)
	 WillDelFiles=NewFiles
	---排除掉新产生的backup文件end--
 
	for a in WillDelFiles do
	(			
		deletefile a
		) 
	----删除导入机制生产的备份文件---
		
	----释放全局变量DIR	
 	free(DIR)
	)
 )

 rollout exportFBX_ue4cam_v2 "批出fb模&UEcam_V2:模式自选" width:200 height:100
 (
HyperLink explain "指定目录即可,不需要打开文件" pos:[25,0] width:200 height:15 color:(color 255 155 0)
edittext selfile "" pos:[10,15] width:140 height:19 text:"...请选择目录"
button btn_browse "..."  pos:[160,15] width:30 height:19
checkBox ignore "忽略backup文件" pos:[60,35] width:100 height:19
label explain1 "输出相机是打开模式,输出模型是导入模式" pos:[0,64] width:200 height:15 
radioButtons rdo1 "" pos:[30,50] width:168 height:16 labels:#("输出相机", "输出模型") default:1 columns:2	 
button	 bt_create	"批量输出fbx" pos:[20,80] width:150 height:32 enabled:true

---函数部分--
 fn LoadOrMergeFile f = (
		 if rdo1.state ==1 then (
			loadMaxfile f missingExtFilesAction:#logmsg
		)
		if rdo1.state ==2 then (
			mergeMaxfile f 
		)
 )  

---------逐行写入文本------------
fn format_txt FilePath filetext1 filetext2=
(	
	if doesFileExist FilePath == true
		then
	(
		fin = openfile FilePath mode:"r+"
		seek fin #eof
		txt = filetext1+RenderWidth as string+"\n"+filetext2+RenderHeight as string+"\n"
		format txt to:fin
		close fin
	)
	else
	(
		newfile = createFile FilePath writeBOM:true
		close newfile
		format_txt FilePath filetext1 filetext2
		)
)
-- 逐行写入文本
			
---///end函数部分--
	 on btn_browse pressed do
 	( 
		global DIR = getSavePath caption:"选择max目录"
		if (DIR != undefined) do ( selfile.text = DIR )	
	)	
	
	 on bt_create pressed do
 	( 
	 files =DIR+"/"+"*.max"
	 OldFiles=getfiles files	
	 GetFile= getFiles files
    if (ignore.checked)then(		
 	 ---排除掉backup文件--
	 WillDelFiles=getfiles (DIR+"\*backup*.max")
	 for j = 1 to WillDelFiles.count do	while (index = (findItem GetFile WillDelFiles[j])) != 0 do (deleteItem GetFile index)
	---排除掉backup文件end-- 
	)
	
	Maxfiles=GetFile 
		 
	 for f in Maxfiles do (
			---切割文本内容
			mydir=trimRight f ".max"
			global FileName=trimLeft mydir DIR
			global FilePath=(DIR+"/"+FileName+".txt") as string	
			--导入max文件--- 
			LoadOrMergeFile f	 
			----输出model.fbx ---		 
	-- 		ExportModel,见 rdo1的写在那里面
			 if rdo1.state ==1 then (
		---选择相机(包括隐藏的)跳过目标物体
		camsArr = for o in cameras where classof o != targetobject collect o
		select camsArr  filter:FilterCameras showHidden:true
		MaxCamSelSet = selection as array	
		------start输出cam.fbx------
		for i in MaxCamSelSet do(
					MAXCAM= i
			
					Freecamera fov:45 targetDistance:314.512 nearclip:1 farclip:1000 nearrange:0 farrange:1000 mpassEnabled:off mpassRenderPerPass:off pos:[0,0,0] isSelected:on
					hide $
					$.name =FileName+"."+i.name --设置相机名称
					UE4CAM =$
					UE4CAM.Position=MAXCAM.position
					UE4CAM.FOV=MAXCAM.FOV
						
					--位置约束
					UE4CAM.Position.controller= Position_Constraint ()
					A = UE4CAM.Position.controller
					A.appendTarget MAXCAM 100
					--方向约束
					UE4CAM.rotation.controller= Orientation_Constraint ()
					B = UE4CAM.rotation.controller
					
					B.appendTarget MAXCAM 100

		--开始塌陷
				local forceUpdate = keyboard.shiftPressed -- if SHIFT is pressed when the macro is called, a viewport redraw is enforced for each timestep to ensure a full update of all controllers
				if forceUpdate then format "MB Collapse: Enforcing full viewport update. This might be slow but will ensure proper updating of all controllers\n"
				
					local p = undefined
					local old_prs_ctrl = copy UE4CAM.transform.controller		-- store old controller for catch()
					with undo on (
						if not forceUpdate then disableSceneRedraw();	-- not using redraw context for max4 compatibility
						-- disableSceneRedraw is problematic as not all scripted controllers are updated!
						try (
							p = Point()								-- create temp point object
							
							-- copy global transform of source object into temp object
							for i = animationRange.start to animationRange.end do (
								if forceUpdate then sliderTime = i	-- set slider time to force a global update of all animation data
								at time i (
									with animate on p.transform = UE4CAM.transform
								)
							)
							-- kill old transform controller and assign new, clean one
							UE4CAM.transform.controller = transform_script()	
							UE4CAM.transform.controller = prs()	
							
							if not (isGroupMember UE4CAM) then UE4CAM.parent = undefined	-- unlink if not in a group
							-- copy temp object animation back into source object
							for i = animationRange.start to animationRange.end do (
								at time i (
									with animate on	UE4CAM.transform = p.transform
								)
							)
							delete p			-- delete temp point obj
							p = undefined
							if not forceUpdate then enableSceneRedraw()
						)--try
					catch(
						format "coder zsz:QQ  : Fatal error - exiting\n"
									if p!=undefined then delete p
									UE4CAM.transform.controller = old_prs_ctrl
									if not forceUpdate then enableSceneRedraw()
						  )-- catch				
					)--with undo
		--塌陷结束
					
					----对齐相机的关键帧到动画范围---
					debb = 10000
					finn=-10000 
					for a in selection do
					(
						if (numKeys a.position.controller > 0)then(
							sortKeys a.controller
							num_keys = numkeys a.position.controller
							starttime = getkeytime a.position.controller 1
							endtime = starttime
							for O = 1 to num_keys do 
							(
						 
								key_time = getkeytime a.position.controller O
								if key_time > endtime then
									 endtime = key_time
							)
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime
						)
						else(
							starttime = 1
							endtime = 100				
							if starttime < debb then debb = starttime
							if endtime > finn then finn = endtime				
							)
					)
					animationRange = interval debb finn	
					----对齐相机的关键帧到动画范围end---	
					
		--------导出fbx文件-------
					CAM=MAXCAM.name
					FBXFileName=DIR+"/"+FileName+"."+CAM+".fbx"
					exportFile FBXFileName #noPrompt selectedOnly:true using:fbxexpp	
				)	
		------end输出cam.fbx------
				 
				------输出cam.txt------
				if MaxCamSelSet.count !=0 then(				
				format_txt FilePath "renderWidth=" "renderHight="
				)
				------end输出cam.txt------
				 
			)
			if rdo1.state ==2 then (

		---------只输出bip模型------------
		--选择所有bip物体
		select $'*bip*' 
		
		mysel= selection as array
		--根据bip选择根
		for f in mysel do(
		fn getRoot node = if isvalidnode node do (while node.parent != undefined do node = node.parent; node)
		aaa=getRoot f
		select aaa
		)
		--根据根选择此层级所有物体
		if selection.count !=0 then(
		fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
		  
		  select (getTheChildren includeParent:true)
		  select (getTheChildren())
		  
		  getTheChildren includeParent:true as array
		  getTheChildren() as array
		)
		-----对齐帧处理-----
					debb = 10000
					finn=-10000 
						for a in selection do
					(
						if  (classof a == BoneGeometry) then(
							if (numKeys a.position.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.position.controller
								starttime = getkeytime a.position.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.position.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
						if (classof a == Biped_Object) then(
							if (numKeys a.transform.controller > 0)then(
								sortKeys a.controller
								num_keys = numkeys a.transform.controller
								starttime = getkeytime a.transform.controller 1
								endtime = starttime
								for O = 1 to num_keys do 
								(
							 
									key_time = getkeytime a.transform.controller O
									if key_time > endtime then
										 endtime = key_time
								)
								if starttime < debb then debb = starttime
								if endtime > finn then finn = endtime
							)
						)
					)
					animationRange = interval debb finn	
	-----end对齐帧处理-----
					
	------------查找蒙皮中具有bip字样的模型并一起选择---------------
		if selection.count !=0 then(		  
			actionMan.executeAction 0 "283"  -- Tools: Unfreeze All
			max unfreeze all
			allTheSkin = for obj in objects where (classof obj==PolyMeshObject)  collect obj
			for f in allTheSkin do(
			skinMods = getclassinstances Skin target:f 
			max modify mode
			modPanel.setCurrentObject f.modifiers[#Skin]
			skinOps.getnumberbones skinMods[1]
			bonename =skinOps.getBoneName skinMods[1] 1 0
			bonename =skinOps.getBoneName skinMods[1] 2 0	
			if findString bonename "Bip" ==1 then (join mysel f)else(deselect f)
			selectmore mysel
			)
		)
		---------只输出bip模型------------
	
				----start 输出model.fbx---	
				if selection.count !=0 then(		
				AA=Dir+"/"+FileName+"."+"model"+".fbx"	
				exportFile  AA #noPrompt selectedOnly:true using:fbxexp
				)
				----end 输出model.fbx---
			) 
			
			 ------重置max场景-------
			resetMaxFile #noPrompt	
		)
	----删除导入机制生产的备份文件---
		
	 ---排除掉新产生的backup文件--
	 NewFiles=getfiles (DIR+"\*.max")
	
	 for j = 1 to OldFiles.count do	while (index = (findItem NewFiles OldFiles[j])) != 0 do (deleteItem NewFiles index)
	 WillDelFiles=NewFiles
	---排除掉新产生的backup文件end--
 
	for a in WillDelFiles do
	(			
		deletefile a
		) 
	----删除导入机制生产的备份文件---
		
	----释放全局变量DIR	
 	free(DIR)
	)
 )

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1620552.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections

NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections(野外的 NERF: 用于无约束照片采集的神经辐射场&#xff09; Abstract 我们提出了一种基于学习的方法来合成新的视图的复杂场景使用只有非结构化的收集野生照片。我们建立在神经辐射场(neRF)的…

深度学习算法简介(一)

目录 ⛳️推荐 前言 1、深度神经网络&#xff08;DNN&#xff09; 2、卷积神经网络&#xff08;CNN&#xff09; 3、残差网络&#xff08;ResNet&#xff09; 4、LSTM&#xff08;长短时记忆网络&#xff09; 5、Word2Vec 6、Transformer 7、生成对抗网络&#xff08;…

MySQL常见的约束

什么是约束&#xff1f; 限制&#xff0c;限制我们表中的数据&#xff0c;保证添加到数据表中的数据准确和可靠性&#xff01;凡是不符合约束的数据&#xff0c;插入时就会失败&#xff0c;插入不进去的&#xff01; 比如&#xff1a;学生信息表中&#xff0c;学号就会约束不…

【IC设计】奇数分频与偶数分频 电路设计(含讲解、RTL代码、Testbench代码)

文章目录 原理分析实现和仿真偶数分频的电路RTL代码偶数分频的电路Testbench代码偶数分频的电路仿真波形占空比为50%的三分频电路RTL代码占空比为50%的三分频电路Testbench代码占空比为50%的三分频电路仿真波形 参考资料 原理分析 分频电路是将给定clk时钟信号频率降低为div_c…

北斗卫星助力农业生产精准播种

北斗卫星助力农业生产精准播种 随着现代化农业的不断进步&#xff0c;高科技技术的融合已成为推动农业生产向前发展的重要动力。其中&#xff0c;北斗卫星导航系统&#xff08;BDS&#xff09;的应用&#xff0c;特别是在农业播种领域的利用&#xff0c;标志着农作物种植方式的…

私域运营的基础是什么?

私域运营是指在自有平台上进行的一系列运营活动&#xff0c;旨在建立和维护与用户的深度互动关系&#xff0c;提升用户忠诚度和品牌影响力。相比于传统的广告投放和推广方式&#xff0c;私域运营更加注重与用户的沟通和互动&#xff0c;通过提供有价值的内容和个性化的服务&…

业务复习知识点Oracle查询

业务数据查询-1 单表查询 数据准备 自来水收费系统建表语句.sql 简单条件查询 精确查询 需求 &#xff1a;查询水表编号为 30408 的业主记录 查询语句 &#xff1a; select * from t_owners where watermeter 30408; 查询结果 &#xff1a; 模糊查询 需求 &#xff1a;查询业…

mysql添加普通索引(简单使用)

前言&#xff1a;以订单表&#xff08;oms_order&#xff09;为例&#xff0c;添加用户id&#xff08;user_id&#xff09;为普通索引 mysql添加普通索引&#xff08;简单使用&#xff09; 1.查看表已经存在的索引情况a.语法b.使用c.结果&#xff08;这里还没有添加所以&#…

MT3029 战神小码哥

注意点&#xff1a;不能先按时间排序&#xff0c;在每个时间点选最大的。如果第一秒有p11&#xff0c;第二秒有p210和p311&#xff0c;则如果按时间来&#xff0c;则先选第一秒的1&#xff0c;再选第二秒的 11&#xff1b;但是有更优的策略&#xff1a;第一秒选p3,第二秒选p2。…

【1431】java学习网站系统Myeclipse开发mysql数据库web结构java编程计算机网页项目

一、源码特点 java 学习网站系统是一套完善的java web信息管理系统&#xff0c;对理解JSP java编程开发语言有帮助&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为TOMCAT7.0,Myeclipse8.5开发&#xff0c;数据库为Mysql5.0&…

ARP 攻击神器:ARP Spoof 保姆级教程

一、介绍 arpspoof是一种网络工具&#xff0c;用于进行ARP欺骗攻击。它允许攻击者伪造网络设备的MAC地址&#xff0c;以欺骗其他设备&#xff0c;并截获其通信。arpspoof工具通常用于网络渗透测试和安全评估&#xff0c;以测试网络的安全性和漏洞。 以下是arpspoof工具的一些…

【考研高数】学习笔记分享

派大星说数学&#xff08;导学部分&#xff09; 关于做题 测试 答疑阶段 直播 群内 高中基础知识导学 一、数与式 述了课程学习和因式分解、分式拆解等知识点。学生应了解课程内容&#xff0c;带着疑问听课&#xff0c;不要抄笔记&#xff0c;导学课和基础课都有测验&…

【Linux】LInux下的进程状态

&#x1f466;个人主页&#xff1a;Weraphael ✍&#x1f3fb;作者简介&#xff1a;目前正在学习c和算法 ✈️专栏&#xff1a;Linux &#x1f40b; 希望大家多多支持&#xff0c;咱一起进步&#xff01;&#x1f601; 如果文章有啥瑕疵&#xff0c;希望大佬指点一二 如果文章对…

海内外电商平台架构探究:技术与商业的融合

随着全球化进程的加速和互联网的普及&#xff0c;电子商务在海内外市场都蓬勃发展。海外电商平台在连接全球买家和卖家、拓展国际市场方面发挥着重要作用&#xff0c;而国内电商平台则在满足国内消费需求、促进国内经济增长方面扮演着关键角色。本文将探讨海内外电商平台的架构…

常见大厂面试题(SQL)01

知乎问答最大连续回答问题天数大于等于3天的用户及其对应等级 1.描述 现有某乎问答创作者信息表author_tb如下(其中author_id表示创作者编号、author_level表示创作者级别&#xff0c;共1-6六个级别、sex表示创作者性别)&#xff1a; author_id author_level sex 101 …

基于STM32的DAC简易信号发生器设计(HAL库)

前言&#xff1a;本文为手把手教学制造 DAC 简易信号发生器的教程&#xff0c;本教程的 MCU 使用 STM32F103ZET6 。以 HAL 库的 DAC 函数作为代码基础进行编程&#xff0c;使得信号发生器可以产生各种类型的信号波&#xff0c;包括&#xff1a;方波、三角波、正弦波和噪声波&am…

Oracle解析exp、imp及常见的问题

前言 在工作中经常需要不同数据库的导入和导出。exp和imp可以实现数据的迁移。 exo会转储产生对应的二进制文件,里面包括数据的定义信息、数据内容等,即为dump文件。 下面是使用exp和imp的一些场景 exp和imp主要有4中模式: 1)数据库模式 数据库模式也就是我们说的全备…

Pytorch 计算深度模型的大小

计算模型大小的方法 卷积 时间复杂度 与 空间复杂度 的计算方式&#xff1a; C 通道的个数&#xff0c;K卷积核大小&#xff0c;M特征图大小&#xff0c;C_l-1是输入通道的个数&#xff0c;C_l是输出通道的个数 1 模型大小 MB 计算模型的大小的原理就是计算保存模型所需要…

sprinboot+人大金仓配置

1. .yml 配置 spring:datasource:type: com.alibaba.druid.pool.DruidDataSource#driverClassName: dm.jdbc.driver.DmDriver## todo 人大金仓driverClassName: com.kingbase8.Driverdruid:## todo 人大金仓master:url: jdbc:kingbase8://111.111.111.111:54321/dbname?cu…

区块链钱包开发——专业区块链开发

随着区块链技术的发展&#xff0c;钱包开发成为了一项至关重要的任务。本文将探讨区块链钱包开发的重要性&#xff0c;分析当前面临的挑战&#xff0c;并展望未来的发展趋势。 一、区块链钱包概述 区块链钱包是一种用于存储和管理数字货币的软件工具。它为用户提供了一个安全的…