人生第一个Max脚本工具

最近刚开始学习Maxscript,作为一名美术从业者当初可从来没想过自己还要跟一堆代码打交道,不过真的接触下来发现其实还是比较有趣的,仿佛打开了新世界的大门。

为了学以致用,找了点需求实践下。

针对项目中角色和场景制作输出过程中的相关问题,为了避免大量的重复操作和错误的命名方式导致的效率低下和引擎报错,利用空闲时间做了一个针对性的脚本:LuckyTools v1.0整合了一些经常使用的检查与修正命令,以及一键命名功能(还在完善,目前可满足基本使用)。后续打算在此基础上完善下,尤其是针对大量的场景材质,让它适用范围更广泛一些。

人生第一个脚本,做的比较简单。

rollout Lucky "LuckyTools v1.0" width:165 height:303
(
	button btn1 "去除2U" pos:[41,72] width:83 height:19
	button btn2 "去顶点色" pos:[41,40] width:83 height:19
	GroupBox clear "Clear" pos:[21,9] width:128 height:151
	button btn3 "去材质" pos:[41,99] width:83 height:19
	GroupBox grp4 "Rename" pos:[21,172] width:124 height:108
	button btn10 "一键命名" pos:[41,206] width:83 height:19
	button btn26 "Info" pos:[41,244] width:83 height:19
	button btn77 "修正光滑组异常" pos:[41,132] width:83 height:19
	on btn1 pressed do
	(
			channelInfo.ClearChannel $ 2
			macros.run "Modifier Stack" "Convert_to_Poly"
		)
	on btn2 pressed do
	(
			channelInfo.ClearChannel $ 0
			macros.run "Modifier Stack" "Convert_to_Poly"
		)
	on btn3 pressed do
		$.material = undefined
	on btn10 pressed do
	(
		for i in selection do (i.material.name = i.name + "_mat")
		for i in selection do (i.material.DiffuseMap.name = i.name + "_d")
		for i in selection do (i.material.SpecularLevelMap.name = i.name + "_m")
		for i in selection do (i.material.BumpMap.name = i.name + "_n_mat")
		for i in selection do (i.material.Bumpmap.Normal_map.name = i.name + "_n")
		)
	on btn26 pressed do
	(
		messagebox "完善中 若有疑问 请联系 hzgedanfeng@corp.netease.com"
	)
	on btn77 pressed do
	(
			modPanel.addModToSelection (Normalmodifier ()) ui:on
			macros.run "Modifier Stack" "Convert_to_Poly"
		)
)
createDialog Lucky

最近针对之前的脚本做了一些修改,尤其是针对自动命名和修复光滑组和法线的问题,做了更多情况的判断。

以下是修改的代码:

rollout lucky "LuckyTools v1.0" width:168 height:397
(
	button btn1 "Clear2U" pos:[40,64] width:95 height:19
	button btn2 "ClearVC" pos:[40,32] width:95 height:19
	GroupBox clear "Clear" pos:[21,8] width:128 height:192
	button btn3 "ClearMat" pos:[40,96] width:95 height:19
	GroupBox grp4 "Rename" pos:[21,216] width:124 height:152
	button btn10 "Rename" pos:[40,247] width:95 height:19
	button btn26 "Info" pos:[40,312] width:95 height:19
	button btn77 "FixSmoothGroup" pos:[40,160] width:95 height:19
	button btn7 "SetID" pos:[40,128] width:95 height:19
	button btn9 "Rename(normal)" pos:[40,280] width:95 height:19
	on btn1 pressed do --去除2U
	(
			channelInfo.ClearChannel $ 2
			macros.run "Modifier Stack" "Convert_to_Poly"
		)
	on btn2 pressed do --去除顶点色
	(
			channelInfo.ClearChannel $ 0
			macros.run "Modifier Stack" "Convert_to_Poly"
		)
	on btn3 pressed do  --去除材质指定
		$.material = undefined
	on btn10 pressed do  --自动命名
	(
		for i in selection do 
	(
		if i.material.name != i.name + "_mat" then i.material.name = i.name + "_mat"
		if i.material.DiffuseMap != undefined then i.material.DiffuseMap.name = i.name + "_d"
		if i.material.SpecularLevelMap != undefined then i.material.SpecularLevelMap.name = i.name + "_m"
	    if i.material.selfillumMap != undefined then i.material.selfillumMap.name = i.name + "_e"
	    if i.material.opacityMap != undefined then i.material.opacityMap.name = i.name + "_o"
	    if i.material.Bumpmap != undefined then i.material.Bumpmap.name = i.name + "_n"
	)
	)
	on btn26 pressed do
	(
		messagebox "完善中 若有疑问 请联系 hzgedanfeng@corp.netease.com"
	)
	on btn77 pressed do  --修正法线和光滑组
	(
		modPanel.setCurrentObject $.baseObject
		modPanel.addModToSelection (Normalmodifier ()) ui:on
			$.modifiers[#Normal].flip = on
		modPanel.addModToSelection (Normalmodifier ()) ui:on
			$.modifiers[#Normal].flip = on
			macros.run "Modifier Stack" "Convert_to_Poly"
			for o in selection do
				(
					theObj = o.baseObject
					numOfFaces = polyop.getnumfaces theObj
					for i = 1 to numOfFaces do
						(
							polyop.setFaceSmoothGroup theObj i 1
							)
	
		        )
	)
	on btn7 pressed do  --设置ID为1
	(
	numoffaces = polyop.getnumfaces $
	for i=1 to numoffaces do polyop.setFaceMatID $ i 1
	)
	on btn9 pressed do  --自动命名(带法线的情况)
	(
		for i in selection do 
	(
		if i.material.name != i.name + "_mat" then i.material.name = i.name + "_mat"
		if i.material.DiffuseMap != undefined then i.material.DiffuseMap.name = i.name + "_d"
		if i.material.SpecularLevelMap != undefined then i.material.SpecularLevelMap.name = i.name + "_m"
	    if i.material.selfillumMap != undefined then i.material.selfillumMap.name = i.name + "_e"
	    if i.material.opacityMap != undefined then i.material.opacityMap.name = i.name + "_o"
	    if i.material.Bumpmap != undefined then i.material.Bumpmap.name = i.name + "_n"
		for i in selection do
	(		
		if i.material.Bumpmap != undefined and i.material.Bumpmap.normal_map.bitmap != undefined
			then i.material.BumpMap.name = i.name + "_n_mat"
		i.material.BumpMap.Normal_map.name = i.name + "_n"
	)
	)
	)
)
createDialog lucky

20170413 迭代

rollout lucky "LuckyTools v1.0" width:168 height:397
(
	button btn1 "Clear2U" pos:[40,64] width:95 height:19
	button btn2 "ClearVC" pos:[40,32] width:95 height:19
	GroupBox clear "Clear" pos:[21,8] width:128 height:192
	button btn3 "ClearMat" pos:[40,96] width:95 height:19
	GroupBox grp4 "Rename" pos:[21,216] width:124 height:152
	button btn10 "Rename" pos:[40,247] width:95 height:19
	button btn26 "Info" pos:[40,312] width:95 height:19
	button btn77 "FixSmoothGroup" pos:[40,160] width:95 height:19
	button btn7 "SetID" pos:[40,128] width:95 height:19
	button btn9 "Rename(normal)" pos:[40,280] width:95 height:19
	on btn1 pressed do --去除2U
	(
			for a in selection do
			(
				channelInfo.ClearChannel a 2
				if a.modifiers[#skin] != undefined then
						(
							paste = copy a.modifiers[#skin]
							macros.run "Modifier Stack" "Convert_to_Poly"
							addmodifier a paste
							)
		)
	)
	on btn2 pressed do --去除顶点色
	(
			for a in selection do 
				(
					channelInfo.ClearChannel a 0
					if a.modifiers[#skin] != undefined then
						(
							paste = copy a.modifiers[#skin]
							macros.run "Modifier Stack" "Convert_to_Poly"
							addmodifier a paste
							)
				)
	)
	on btn3 pressed do  --去除材质指定
	(
		for a in selection do a.material = undefined
		)
	on btn10 pressed do  --自动命名
	(
		for i in selection do 
	(
		if i.material.name != i.name + "_mat" then i.material.name = i.name + "_mat"
		if i.material.DiffuseMap != undefined then i.material.DiffuseMap.name = i.name + "_d"
		if i.material.SpecularLevelMap != undefined then i.material.SpecularLevelMap.name = i.name + "_m"
	    if i.material.selfillumMap != undefined then i.material.selfillumMap.name = i.name + "_e"
	    if i.material.opacityMap != undefined then i.material.opacityMap.name = i.name + "_o"
	    if i.material.Bumpmap != undefined then i.material.Bumpmap.name = i.name + "_n"
	)
	)
	on btn26 pressed do
	(
		messagebox "完善中 若有疑问 请联系 hzgedanfeng@corp.netease.com"
	)
	on btn77 pressed do  --修正法线和光滑组
	(
		for a in selection do
		(
		modPanel.setCurrentObject a.baseObject
		modPanel.addModToSelection (Normalmodifier ()) ui:on
			a.modifiers[#Normal].flip = on
		modPanel.addModToSelection (Normalmodifier ()) ui:on
			a.modifiers[#Normal].flip = on
				if a.modifiers[#skin] != undefined then
						(
							paste = copy a.modifiers[#skin]
							macros.run "Modifier Stack" "Convert_to_Poly"
							addmodifier a paste
							)
			for o in selection do
				(
					theObj = o.baseObject
					numOfFaces = polyop.getnumfaces theObj
					for i = 1 to numOfFaces do
						(
							polyop.setFaceSmoothGroup theObj i 1
							)
	
		        )
			)
	)
	on btn7 pressed do  --设置ID为1
	(
	numoffaces = polyop.getnumfaces $
	for i=1 to numoffaces do polyop.setFaceMatID $ i 1
	)
	on btn9 pressed do  --自动命名(带法线的情况)
	(
		for i in selection do 
	(
		if i.material.name != i.name + "_mat" then i.material.name = i.name + "_mat"
		if i.material.DiffuseMap != undefined then i.material.DiffuseMap.name = i.name + "_d"
		if i.material.SpecularLevelMap != undefined then i.material.SpecularLevelMap.name = i.name + "_m"
	    if i.material.selfillumMap != undefined then i.material.selfillumMap.name = i.name + "_e"
	    if i.material.opacityMap != undefined then i.material.opacityMap.name = i.name + "_o"
	    if i.material.Bumpmap != undefined then i.material.Bumpmap.name = i.name + "_n"
		for i in selection do
	(		
		if i.material.Bumpmap != undefined and i.material.Bumpmap.normal_map.bitmap != undefined
			then i.material.BumpMap.name = i.name + "_n_mat"
		i.material.BumpMap.Normal_map.name = i.name + "_n"
	)
	)
	)
)
createDialog lucky

2017.4.25更新迭代,新增自定义命名功能,可以大批量处理

--============================================
--CheckAndNaming v1.0
--Dev support:葛丹峰(hzgedanfeng)
--============================================

rollout lucky "CheckAndNaming v1.0" width:469 height:435
(
	button clear2U "去除2U" pos:[35,284] width:95 height:19
	button clearvc "去顶点色" pos:[35,253] width:95 height:19
	GroupBox batchfix "批量修改" pos:[16,200] width:128 height:216
	button ClearMat "去材质" pos:[35,316] width:95 height:19
	GroupBox rename "命名" pos:[168,199] width:128 height:217
	button mingming "一键命名" pos:[184,232] width:95 height:19
	button info "信息" pos:[336,320] width:95 height:19
	button FixSmoothGroup "修复光滑组异常" pos:[35,380] width:95 height:19
	button SetID "统一ID" pos:[35,348] width:95 height:19
	GroupBox zidingyi "自定义命名" pos:[312,15] width:144 height:288
	edittext prefix "前缀名" pos:[323,34] width:120 height:20
	edittext diffusesuffix "Diffuse后缀" pos:[323,114] width:120 height:20
	button batchname "批量命名" pos:[336,250] width:96 height:31
	edittext basename "基础名" pos:[323,61] width:120 height:20 enabled:true
	bitmap bmp3 "Bitmap" pos:[168,253] width:0 height:0
	label lbl12 "*命名仅针对材质面板,不会改变本地贴图的名字,无前后缀名可留空处理。" pos:[312,359] width:144 height:48
	edittext mixmapsuffix "Mixmap后缀" pos:[323,138] width:120 height:20
	edittext normalsuffix "Normal后缀" pos:[323,210] width:120 height:20
	edittext matsuffix "Mat后缀" pos:[324,90] width:120 height:20
	edittext opacitysuffix "Opacity后缀" pos:[323,186] width:120 height:20
	edittext selfillumsuffix "Selfillum后缀" pos:[320,162] width:120 height:20
	button ResetXForm "ResetXform" pos:[35,224] width:95 height:19
	checkbox checknormal "Normal Bump" pos:[189,264] width:89 height:24 enabled:true checked:true
	GroupBox piliangjiancha "批量检查" pos:[16,16] width:280 height:176
	button batchcheck "批量检查" pos:[56,48] width:200 height:40
	label lbl2 "*请先确认好模型命名,默认材质贴图按模型名+“_d,_m,_o,_e,_n”命名,材质为_mat" pos:[176,336] width:112 height:68
	listbox lbx1 "ListBox" pos:[56,104] width:200 height:3 selection:1
	------------------------------------------
	global sel = selection as array
	--------------------------------------------
	fn checkSel =
	(
		sel = getCurrentSelection()
		sel1 = #()
		if sel.count == 0 then messagebox "请先选择要操作的物体!"
			for i in sel do
			(
				if classof i == editable_poly do join sel1 i
				)
				return sel1
			)
	----------------------------------------------		

	on clear2U pressed do
	(
		checkSel()
			for a=1 to sel.count do
			(
				channelInfo.ClearChannel sel[a] 2
				if sel[a].modifiers[#skin] != undefined then
						(
							paste = copy sel[a].modifiers[#skin]
							macros.run "Modifier Stack" "Convert_to_Poly"
							addmodifier sel[a] paste
							)
							else macros.run "Modifier Stack" "Convert_to_Poly"
		)
	)
	on clearvc pressed do
	(
		checkSel()
		for a =1 to sel.count do
				(
					channelInfo.ClearChannel sel[a] 0
					if sel[a].modifiers[#skin] != undefined then
						(
							paste = copy sel[a].modifiers[#skin]
							macros.run "Modifier Stack" "Convert_to_Poly"
							addmodifier sel[a] paste
							)
							else macros.run "Modifier Stack" "Convert_to_Poly"
				)
	)
	on ClearMat pressed do
	(
		checkSel()
		for a = 1 to sel.count do sel[a].material = undefined
	)
	on mingming pressed do
	(
		checkSel()
	for i= 1 to sel.count do 
		(
			if sel[i].material.name != sel[i].name + "_mat" then sel[i].material.name = sel[i].name + "_mat"
			if sel[i].material.DiffuseMap != undefined then sel[i].material.DiffuseMap.name = sel[i].name + "_d"
			if sel[i].material.SpecularLevelMap != undefined then sel[i].material.SpecularLevelMap.name = sel[i].name + "_m"
		    if sel[i].material.selfillumMap != undefined then sel[i].material.selfillumMap.name = sel[i].name + "_e"
		    if sel[i].material.opacityMap != undefined then sel[i].material.opacityMap.name = sel[i].name + "_o"
		if checknormal.checked == true then 
			sel[i].material.Bumpmap.normal_map.name = sel[i].name + "_n"
		    sel[i].material.Bumpmap.name = sel[i].name + "_n_mat"
			if checknormal.checked == false then sel[i].material.Bumpmap.name = sel[i].name + "_n"
		)	
		)
	on info pressed do
	(
		messagebox "完善中 若有疑问 请联系 hzgedanfeng@corp.netease.com"
	)
	on FixSmoothGroup pressed do
	(
		checkSel()
		for a=1 to sel.count do
		(
		modPanel.setCurrentObject sel[a].baseObject
		modPanel.addModToSelection (Normalmodifier ()) ui:on
			sel[a].modifiers[#Normal].flip = on
		modPanel.addModToSelection (Normalmodifier ()) ui:on
			sel[a].modifiers[#Normal].flip = on
				if sel[a].modifiers[#skin] != undefined then
						(
							paste = copy sel[a].modifiers[#skin]
							macros.run "Modifier Stack" "Convert_to_Poly"
							addmodifier sel[a] paste
							)
							else macros.run "Modifier Stack" "Convert_to_Poly"
			for o in selection do
				(
					theObj = o.baseObject
					numOfFaces = polyop.getnumfaces theObj
					for i = 1 to numOfFaces do
						(
							polyop.setFaceSmoothGroup theObj i 1
							)
	
		        )
			)
	)
	on SetID pressed do
	(
	checkSel()
	for i=1 to sel.count do
	(
		if sel[i].modifiers[#skin] != undefined then
						(
							paste = copy sel[i].modifiers[#skin]
							macros.run "Modifier Stack" "Convert_to_Poly"
							subobjectLevel = 5	
	                        numoffaces = polyop.getnumfaces sel[i]
	                        for j=1 to numoffaces do polyop.setFaceMatID sel[i] j 1
		                    subobjectLevel = 0
							addmodifier sel[i] paste
							)
	else 
	subobjectLevel = 5	
	numoffaces = polyop.getnumfaces sel[i]
	for j=1 to numoffaces do polyop.setFaceMatID sel[i] j 1
	subobjectLevel = 0
	)
	)
	on batchname pressed do
	(
		checkSel()
		for i=1 to sel.count do
	(
	if sel[i].material.name != prefix.text + basename.text + matsuffix.text then sel[i].material.name = prefix.text + basename.text + matsuffix.text
	if sel[i].material.DiffuseMap != undefined then sel[i].material.DiffuseMap.name = prefix.text + basename.text + diffusesuffix.text
	if sel[i].material.SpecularLevelMap != undefined then sel[i].material.SpecularLevelMap.name = prefix.text + basename.text + mixmapsuffix.text
	if sel[i].material.selfillumMap != undefined then sel[i].material.selfillumMap.name = prefix.text + basename.text + selfillumsuffix.text
	if sel[i].material.opacityMap != undefined then sel[i].material.opacityMap.name = prefix.text + basename.text + opacitysuffix.text
	)
		for i=1 to sel.count do
		(		
			if sel[i].material.Bumpmap != undefined and sel[i].material.Bumpmap.normal_map.bitmap != undefined
				then sel[i].material.BumpMap.name = prefix.text + basename.text + "_n_mat"
			sel[i].material.BumpMap.Normal_map.name = prefix.text + basename.text + normalsuffix.text
		)
		)
	on ResetXForm pressed do
	(
		checkSel()
			for a=1 to sel.count do 
				(
					if sel[a].scale != [1,1,1] then resetxform a ; macros.run "Modifier Stack" "Convert_to_Poly"
					)
	)
	on batchcheck pressed do
	(
	checkSel()		
	if selection.count == 0 then ( messageBox "请先选择要操作的物体" )
		else
		for i in selection do ChannelInfo.dialog() 
	
	)
)
createDialog lucky

2017.4.27更新

--============================================
--CheckAndNaming v1.0 (2017.4.27)
--Dev support:葛丹峰(hzgedanfeng@corp.netease.com)
--============================================
try closeRolloutFloater CAN catch()
rollout batchcheck "批量检查" width:300 height:160
(
	button Bcheck "批量检查" pos:[25,14] width:250 height:50
	listbox list "列表" pos:[26,72] width:249 height:3
--//
	global sel = selection as array
------------------------------------
	fn checkSel =
	(
		sel = getCurrentSelection()
		sel1 = #()
		if sel.count == 0 then messagebox "请先选择要操作的物体!"
			for i in sel do
			(
				if classof i == editable_poly do join sel1 i
				)
				return sel1
			)
	fn getCPVobj =
	(
		sel = getCurrentSelection()
		CPVobj = #()
	    if classof sel != editable_mesh do ConvertToMesh sel
		for a=1 to sel.count do
		(
			if getnumCPVverts sel[a] != 0 then append CPVobj sel[a]
			)
		for i=1 to CPVobj.count do 
		(
			if classof CPVobj[i] != editable_poly then ConvertTopoly CPVobj[i]
			)
		)
--//
on Bcheck pressed do
	(		
	    getCPVobj()
		listbox list "列表" items:(for o in CPVobj collect o.name)
	)
	on list selected nameIndex do
		select (getNodeByName list.items[nameIndex])
	
)
rollout batchfix "批量修复" width:300 height:144
(
	button clear2U "去除2U" pos:[157,57] width:100 height:25
	button clearvc "去顶点色" pos:[157,17] width:100 height:25
	button clearmat "去除材质" pos:[44,17] width:100 height:25
	button setID "统一ID" pos:[44,97] width:100 height:25
	button Wresetxform "ResetXform" pos:[44,57] width:100 height:25
	button fixSG "修复光滑组异常" pos:[157,97] width:100 height:25
--//
	global sel = selection as array
	------------------------------------
	fn checkSel =
	(
		sel = getCurrentSelection()
		sel1 = #()
		if sel.count == 0 then messagebox "请先选择要操作的物体!"
			for i in sel do
			(
				if classof i == editable_poly do join sel1 i
				)
				return sel1
			)
	on clear2U pressed do
	(
			checkSel()
				for a=1 to sel.count do
				(
					if sel[a].modifiers[#skin] != undefined then
							(
								channelInfo.ClearChannel sel[a] 2
									paste = copy sel[a].modifiers[#UVWMappingClear]
									pasteS = copy sel[a].modifiers[#skin]
									modPanel.setCurrentObject sel[a].baseObject
									addmodifier sel[a] paste
									converttopoly sel[a]
									addmodifier sel[a] pasteS
									)
									else 
									(
										channelInfo.ClearChannel sel[a] 2
										converttopoly sel[a]
									)
			)
		)
	on clearvc pressed do
	(
			checkSel()
			for a =1 to sel.count do
					(
						if sel[a].modifiers[#skin] != undefined then
							(
								channelInfo.ClearChannel sel[a] 0
									paste = copy sel[a].modifiers[#UVWMappingClear]
									pasteS = copy sel[a].modifiers[#skin]
									modPanel.setCurrentObject sel[a].baseObject
									addmodifier sel[a] paste
									converttopoly sel[a]
									addmodifier sel[a] pasteS
									)
									else 
									(
										channelInfo.ClearChannel sel[a] 0
										converttopoly sel[a]
									)
					)
	)
	on clearmat pressed do
	(
			checkSel()
			for a = 1 to sel.count do sel[a].material = undefined
		)
	on setID pressed do
	(
		checkSel()
		for i=1 to sel.count do
		(
			if sel[i].modifiers[#skin] != undefined then
							(
								if classof sel != editable_poly do ConvertToPoly sel
								modPanel.setCurrentObject sel[i].baseObject
								subobjectLevel = numSubObjectLevels	
		                        numoffaces = polyop.getnumfaces sel[i]
		                        for j=1 to numoffaces do polyop.setFaceMatID sel[i] j 1
			                    subobjectLevel = 0
								)
								else
								(
								subobjectLevel = 5
		                        numoffaces = polyop.getnumfaces sel[i]
		                        for j=1 to numoffaces do polyop.setFaceMatID sel[i] j 1
			                    subobjectLevel = 0	
								)
		)
		)
	on Wresetxform pressed do
	(
		checkSel()
		for a=1 to sel.count do 
						(
							if sel[a].modifiers[#skin] != undefined then
								(
									pasteS = copy sel[a].modifiers[#skin]
									modPanel.setCurrentObject sel[a].baseObject
									resetxform sel[a]
									converttopoly sel[a]
									addmodifier sel[a] pasteS
							)
							if sel[a].modifiers[#skin] == undefined then
							(
								modPanel.setCurrentObject sel[a].baseObject
								resetxform sel[a]
								converttopoly sel[a]
							)
		                )
		)
	on fixSG pressed do
	(
			checkSel()
			for a=1 to sel.count do
			(
			modPanel.setCurrentObject sel[a].baseObject
			modPanel.addModToSelection (Normalmodifier ()) ui:on
				sel[a].modifiers[#Normal].flip = on
			modPanel.addModToSelection (Normalmodifier ()) ui:on
				sel[a].modifiers[#Normal].flip = on
					if sel[a].modifiers[#skin] != undefined then
							(
								paste = copy sel[a].modifiers[#skin]
								macros.run "Modifier Stack" "Convert_to_Poly"
								addmodifier sel[a] paste
								)
								else macros.run "Modifier Stack" "Convert_to_Poly"
				for o in selection do
					(
						theObj = o.baseObject
						numOfFaces = polyop.getnumfaces theObj
						for i = 1 to numOfFaces do
							(
								polyop.setFaceSmoothGroup theObj i 1
								)
		
			        )
				)
	)
)
rollout OneNaming "一键命名" width:300 height:168
(
	button Naming "一键命名" pos:[73,16] width:150 height:32
	checkbox checknormal "Normal Bump" pos:[90,57] width:125 height:15 enabled:true checked:true
	label lbl3 "①请先确认模型命名" pos:[77,78] width:150 height:16
	------------------------------------------
	global sel = selection as array
	--------------------------------------------
	fn checkSel =
	(
		sel = getCurrentSelection()
		sel1 = #()
		if sel.count == 0 then messagebox "请先选择要操作的物体!"
			for i in sel do
			(
				if classof i == editable_poly do join sel1 i
				)
				return sel1
			)
	----------------------------------------------		

	label lbl4 "②默认材质和贴图名按模型名+对应后缀组成" pos:[77,94] width:150 height:32
	label lbl5 "③默认设置为“_mat,_d,_m,_o,_e,_n”" pos:[77,126] width:150 height:32
	on Naming pressed do
	(
		checkSel()
		/*for i=1 to sel.count do 
			(
				if sel[i].material.name != sel[i].name + "_mat" then sel[i].material.name = sel[i].name + "_mat"
				if sel[i].material.DiffuseMap != undefined then sel[i].material.DiffuseMap.name = sel[i].name + "_d"
				if sel[i].material.SpecularLevelMap != undefined then sel[i].material.SpecularLevelMap.name = sel[i].name + "_m"
			    if sel[i].material.selfillumMap != undefined then sel[i].material.selfillumMap.name = sel[i].name + "_e"
			    if sel[i].material.opacityMap != undefined then sel[i].material.opacityMap.name = sel[i].name + "_o"
		if checknormal.checked == false and sel[i].material.Bumpmap == undefined then none
				if checknormal.checked == false and sel[i].material.Bumpmap != undefined then
				sel[i].material.Bumpmap.name = sel[i].name + "_n"
			    if checknormal.checked == true then 
				(
			    sel[i].material.Bumpmap.name = sel[i].name + "_n_mat"
		         sel[i].material.Bumpmap.normal_map.name = sel[i].name + "_n"
	               )
			)*/
		for i in sel do 
			(
				if i.material.name != i.name + "_mat" then i.material.name = i.name + "_mat"
				if i.material.DiffuseMap != undefined then i.material.DiffuseMap.name = i.name + "_d"
				if i.material.SpecularLevelMap != undefined then i.material.SpecularLevelMap.name = i.name + "_m"
			    if i.material.selfillumMap != undefined then i.material.selfillumMap.name = i.name + "_e"
			    if i.material.opacityMap != undefined then i.material.opacityMap.name = i.name + "_o"
					if checknormal.checked == false and i.material.Bumpmap == undefined then none
				if checknormal.checked == false and i.material.Bumpmap != undefined then 
					i.material.Bumpmap.name = i.name + "_n"
			    if checknormal.checked == true and i.material.Bumpmap.name != undefined then 
			    (
				i.material.Bumpmap.name = i.name + "_n_mat"
				i.material.Bumpmap.normal_map.name = i.name + "_n"
				)
			)
	)
)
rollout zidingyi "自定义命名" width:300 height:328
(
	button batchname "批量命名" pos:[72,236] width:150 height:32
	edittext prefix "前缀名" pos:[77,14] width:150 height:16
	edittext baseName "基础名" pos:[77,42] width:150 height:16
	edittext matsuffix "Mat后缀" pos:[77,70] width:150 height:16
	edittext diffusesuffix "Diffuse后缀" pos:[75,98] width:150 height:16
	edittext mixmapsuffix "Mixmap后缀" pos:[76,126] width:150 height:16
	edittext selfillumsuffix "Selfillum后缀" pos:[76,154] width:150 height:16
	edittext opacitysuffix "Opacity后缀" pos:[76,182] width:150 height:16
	edittext normalsuffix "Normal后缀" pos:[77,210] width:150 height:16
	label lbl6 "命名仅针对材质面板,不会改变本地贴图文件名字,无前后缀可留空处理" pos:[73,279] width:150 height:41
	------------------------------------------
	global sel = selection as array
	--------------------------------------------
	fn checkSel =
	(
		sel = getCurrentSelection()
		sel1 = #()
		if sel.count == 0 then messagebox "请先选择要操作的物体!"
			for i in sel do
			(
				if classof i == editable_poly do join sel1 i
				)
				return sel1
			)
	----------------------------------------------	

	on batchname pressed do
	(
			checkSel()
			for i=1 to sel.count do
		(
		if sel[i].material.name != prefix.text + basename.text + matsuffix.text then sel[i].material.name = prefix.text + basename.text + matsuffix.text
		if sel[i].material.DiffuseMap != undefined then sel[i].material.DiffuseMap.name = prefix.text + basename.text + diffusesuffix.text
		if sel[i].material.SpecularLevelMap != undefined then sel[i].material.SpecularLevelMap.name = prefix.text + basename.text + mixmapsuffix.text
		if sel[i].material.selfillumMap != undefined then sel[i].material.selfillumMap.name = prefix.text + basename.text + selfillumsuffix.text
		if sel[i].material.opacityMap != undefined then sel[i].material.opacityMap.name = prefix.text + basename.text + opacitysuffix.text
		)
			for j=1 to sel.count where
			(		
				sel[j].material.Bumpmap != undefined and sel[j].material.Bumpmap.normal_map.bitmap != undefined
			)
			do
			(
				sel[j].material.BumpMap.name = prefix.text + basename.text + normalsuffix.text + "_mat"
				sel[j].material.BumpMap.Normal_map.name = prefix.text + basename.text + normalsuffix.text
			)
		)
)
rollout info "About" width:296 height:112
(
	label readme "脚本名:CAN (CheckAndNaming)工具集" pos:[45,20] width:210 height:20
	label lbl2 "使用中若有任何问题,请联系:葛丹峰(hzgedanfeng@corp.netease.com)" pos:[45,42] width:210 height:35
	label lbl4 "版本:v1.0(2017.4.27)作者:葛丹峰" pos:[45,79] width:210 height:35
)
CAN = newRolloutFloater "CheckAndNaming v1.0" 300 600
addRollout batchcheck CAN
addRollout batchfix CAN
addRollout OneNaming CAN
addRollout zidingyi CAN
addRollout info CAN




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值