3ds Max maxscript saving parameter setting for mapping controllers to morphers

有些時候需要用到這樣的功能,把來自其他animation application的morpher set轉成另一組 controllers / morphers。這時候就需要弄個 mapping,然後就少不了參數設定... so..

rollout allControls "Mapping FaceShift FacialController Parameter Setting"
(
	global arrController = #()
	global arrPosition = #()
	
	global arrMorpher = #()

	function selectHierarchy =
	(
		for p in selection do
		(
			if p.children != undefined do
			(
				selectmore p.children
			)
		)
	)
	
	fn fnLoadControllers panel_name =
	(
		execute("select $" + panel_name + "")
		selectHierarchy()
		
		for c in selection do
		(
			if classof c == SplineShape then
			(
				index =findString (c as string) "cir"
				
				if index != undefined then
				(
					if index > 0 then
					(
						append arrController (substring (c as string) index ((findString (c as string) "@")-index-1))
						
						strtmp = substring (c as string) ((findString (c as string) "@")+2) -1
						
						execute("append arrPosition (" + strtmp + " as Point3)")
					)
				)
			)
		)
		
	)
	
	
	fn fntest =
	(
		streamOut = openFile "c:\\Mapping FaceShift FacialController Parameter Setting.txt" mode:"w"
		
		format "--Grid Scale = 25.4\n" to:streamOut
		for i = 1 to 46 do
		(
			strtmp = ""
			slidertime = i
			
			strtmp = strtmp + (i as string) + ":"
			bdata = false
			for j = 1 to arrController.count do
			(
				execute("obj = $" + arrController[j])
	
				if (in coordsys parent obj.position) != ([0,0,0] as Point3) then
				(
					if bdata == false then
						strtmp = strtmp + arrController[j]
					else
						strtmp = strtmp + "|" + arrController[j]
					
					strtmp = strtmp + ((in coordsys parent obj.position) as string)
					bdata = true
				)
			)
			
			if i == 46 then
				format "%" strtmp to:streamOut
			else
				format "%\n" strtmp to:streamOut
		)
		
		print (streamOut as string)
		
		flush streamOut
		close streamOut
		
		Messagebox "save to c:\\Mapping FaceShift FacialController Parameter Setting.txt"
	)
	
edittext tbControllerPanel "Controller Set:" text:"facial_UI_All" width:150 text:"" across:2
button bReload "Reload Controllers" width:100 align:#left on bReload pressed do fnLoadControllers(tbControllerPanel.text)

button btest "Dump Parameters" width:200 align:#left on btest pressed do fntest()
) 

createDialog allControls 400 200