对最初脚本的扩展完善版本CheckAndNaming Tool

实现对MAX场景中的模型,批量检查2U和顶点色,批量修复功能(去顶点色、去除2U、统一ID、修复光滑组或法线异常、ResetXform等功能),普通材质球和多维子材质球的一键命名功能,多维子材质的命名目前只能针对自己项目的命名规则,后续考虑将目前实现不太好的自定义命名功能迭代下,使之可以能用配置文件。But,现在都还不知道怎么来写配置文件,若有好心人求指路,多谢~

目前的界面不太好,比较长,虽然设置成了单独的卷展栏可以单独收起,但还是偏长了。


--============================================
--CheckAndNaming v1.0 (2017.4.27)
--Dev support:葛丹峰(hzgedanfeng@corp.netease.com)
--============================================
try closeRolloutFloater CAN catch()
rollout batchcheck "批量检查" width:296 height:216
(
	button Bcheck "批量检查" pos:[25,13] width:250 height:33
	listbox list "有顶点色" pos:[26,56] width:249 height:3
--//
   global CPVobj = #()
	global CPVobj1 = #()
   global UV2obj = #()
	global UV2obj1 = #()
	fn getCPVobj =
	(
		sel = getCurrentSelection()
		for a=1 to sel.count do
		(
		if sel[a].modifiers[#skin] != undefined and classof sel[a] != editable_mesh then
							(
								paste = copy sel[a].modifiers[#skin]
								ConvertToMesh sel[a]
		                        (
			                    if getnumCPVverts sel[a] != 0 then append CPVobj sel[a].name
								if getnumCPVverts sel[a] != 0 then append CPVobj1 sel[a]
			                    print CPVobj
			                    )
								converttopoly sel[a]
								addmodifier sel[a] paste
							   )
		)
		for a=1 to sel.count do
		(
		if sel[a].modifiers[#skin] != undefined and classof sel[a] == editable_mesh then
							(
								paste = copy sel[a].modifiers[#skin]
		                        (
			                    if getnumCPVverts sel[a] != 0 then append CPVobj sel[a].name
								if getnumCPVverts sel[a] != 0 then append CPVobj1 sel[a]
			                    print CPVobj
			                    )
								converttopoly sel[a]
								addmodifier sel[a] paste
							   )
		)
		for a=1 to sel.count do
		(
		if sel[a].modifiers[#skin] == undefined and classof sel[a] != editable_mesh then
								(
									ConvertToMesh sel
								    (
			                        if getnumCPVverts sel[a] != 0 then append CPVobj sel[a].name
									if getnumCPVverts sel[a] != 0 then append CPVobj1 sel[a]
			                        print CPVobj
                                    ConvertTopoly sel[a] 
									)
		                         )
										
		)
		for a=1 to sel.count do
		(
		if classof sel[a] == editable_mesh then
								(
			                        if getnumCPVverts sel[a] != 0 then append CPVobj sel[a].name
									if getnumCPVverts sel[a] != 0 then append CPVobj1 sel[a]
			                        print CPVobj
                                    ConvertTopoly sel[a] 
		                         )
										
		)
	)
	    
		fn getUV2obj =
	(
		sel = getCurrentSelection()
		for a=1 to sel.count do
		(
			if sel[a].modifiers[#skin] != undefined and classof sel[a] != editable_poly then
						(
							 paste = copy sel[a].modifiers[#skin]
							 ConvertToPoly sel[a]
		                     (
			                 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj sel[a].name
								 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj1 sel[a]
							 print UV2obj
							 )
			                 addmodifier sel[a] paste
						)
		)
		for a=1 to sel.count do
		(
			if sel[a].modifiers[#skin] != undefined and classof sel[a] == editable_poly then
						(
							 paste = copy sel[a].modifiers[#skin]
		                     (
			                 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj sel[a].name
								 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj1 sel[a]
							 print UV2obj
							 )
			                 addmodifier sel[a] paste
						)
		)
		for a=1 to sel.count do
		(
			if sel[a].modifiers[#skin] == undefined and classof sel[a] != editable_poly then
						(
							 ConvertToPoly sel[a]
		                     (
			                 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj sel[a].name
								 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj1 sel[a]
							 print UV2obj
							 )
						)
		)
		for a=1 to sel.count do
		(
			if sel[a].modifiers[#skin] == undefined and classof sel[a] == editable_poly then
						(
		                     (
			                 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj sel[a].name
								 if polyop.GetMapSupport sel[a] 2 == true then append UV2obj1 sel[a]
							 print UV2obj
							 )
						)
		)
	)
--//

	listbox has2U "存在2U" pos:[24,126] width:249 height:3
	on Bcheck pressed do
	(		
	   getCPVobj()
		getUV2obj()
	 
	     list.items =  CPVobj
		 has2U.items = UV2obj
		
	)
	on list selected nameIndex do
		
		select (getNodeByName list.items[nameIndex])
		--
	on list doubleClicked nameIndex do
		--select CPVobj
		select (for o in CPVobj1 where o.name!=undefined collect o)
	on has2U selected nameIndex do
		select (getNodeByName has2U.items[nameIndex])
	on has2U doubleClicked nameIndex do
		--select UV2obj
		select (for a in UV2obj1 where a.name!=undefined collect a)
)
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
							(
								pasteS = copy sel[i].modifiers[#skin]
								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
								addmodifier sel[i] pasteS
								)
								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 multiname "多维子材质命名" width:296 height:248
(
	button yijian "一键命名" pos:[56,7] width:187 height:22
	checkbox isnormalbump "Normal Bump" pos:[61,40] width:175 height:15 checked:true
	label lbl2 "①基于模型命名,请先确认模型名" pos:[59,85] width:182 height:19
	label lbl3 "②子材质基础名为:主材质_字母(a、b、c...)" pos:[59,105] width:182 height:32
	label lbl4 "③子材质贴图名为:主材质_序列(01、02、03...)" pos:[59,136] width:182 height:32
	label lbl5 "④子材质贴图后缀为:_d、_m、_n" pos:[59,168] width:182 height:18
	label lbl6 "⑤目前最大支持9个子材质,不建议超过此数,不要有空材质球" pos:[59,188] width:182 height:32
	---------------------------
	global sel = getCurrentSelection()
	global xulie = #("01","02","03","04","05","06","07","08","09")
	global abc = #("a","b","c","d","e","f","g","h","i")
	-------------------------
	on yijian pressed do
	(
		for i=1 to sel.count do 
		(
			for j=1 to sel[i].material.numsubs do
		(
			if sel[i].material.name != sel[i].name + "_mat" 
				then sel[i].material.name = sel[i].name + "_mat"
			if sel[i].material.materiallist [j] != undefined 
				then sel[i].material.materiallist [j].name = sel[i].name + "_" + abc[i] + "_mat"
			----------------
			if sel[i].material.materiallist [j] != undefined and sel[i].material.materiallist [i].diffusemap != undefined
				then sel[i].material.materiallist [j].diffusemap.name = sel[i].name + "_" + xulie[i] + "_d"
			if sel[i].material.materiallist [j] != undefined and sel[i].material.materiallist [i].SpecularLevelMap != undefined
				then sel[i].material.materiallist [j].SpecularLevelMap.name = sel[i].name + "_"  + xulie[i] + "_m"
			----------------------------
			if isnormalbump.checked == false and sel[i].material.materiallist [j].BumpMap == notexture() then contiue
			if isnormalbump.checked == false and sel[i].material.materiallist [j].BumpMap != notexture() then 
				sel[i].material.materiallist [i].Bump_Map.name = sel[i].name + "_" + xulie[i] + "_n"
			if isnormalbump.checked == true and sel[i].material.materiallist [j].BumpMap != undefined then 
			(
				sel[i].material.materiallist [j].BumpMap.name = sel[i].name + "_" + xulie[i] + "_n_mat"
				sel[i].material.materiallist [j].BumpMap.normal_map.name = sel[i].name + "_" + xulie[i] + "_n"
			)
		)
		)
	)
)
rollout zidingyi "自定义命名" width:300 height:328
(
	button batchname "批量命名" pos:[72,226] width:150 height:20
	edittext prefix "前缀名" pos:[77,14] width:150 height:16
	edittext matsuffix "Mat后缀" pos:[77,39] width:150 height:16
	edittext diffusesuffix "Diffuse后缀" pos:[77,67] width:150 height:16
	edittext mixmapsuffix "Mixmap后缀" pos:[77,95] width:150 height:16
	edittext selfillumsuffix "Selfillum后缀" pos:[77,123] width:150 height:16
	edittext opacitysuffix "Opacity后缀" pos:[77,151] width:150 height:16
	edittext normalsuffix "Normal后缀" pos:[77,179] width:150 height:16
	label lbl6 "命名仅针对材质面板,不会改变本地贴图文件名字,无前后缀可留空处理" pos:[73,256] width:150 height:48
	checkbox hasnormalbump "Normal Bump" pos:[75,200] width:104 height:20 checked:true
	------------------------------------------
	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 + sel[i].name + matsuffix.text then sel[i].material.name = prefix.text + sel[i].name + matsuffix.text
		if sel[i].material.DiffuseMap != undefined then sel[i].material.DiffuseMap.name = prefix.text + sel[i].name + diffusesuffix.text
		if sel[i].material.SpecularLevelMap != undefined then sel[i].material.SpecularLevelMap.name = prefix.text + sel[i].name + mixmapsuffix.text
		if sel[i].material.selfillumMap != undefined then sel[i].material.selfillumMap.name = prefix.text + sel[i].name + selfillumsuffix.text
		if sel[i].material.opacityMap != undefined then sel[i].material.opacityMap.name = prefix.text + sel[i].name + 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
			)*/
		for j=1 to sel.count do
			(	
				if hasnormalbump.checked == false and sel[j].material.Bumpmap == undefined then none
				if hasnormalbump.checked == false and sel[j].material.Bumpmap != undefined 
					then sel[j].material.BumpMap.name = prefix.text + sel[i].name + normalsuffix.text
				if sel[j].material.Bumpmap != undefined and sel[j].material.Bumpmap.normal_map.bitmap != undefined
			then
			(
				sel[j].material.BumpMap.name = prefix.text + sel[i].name + normalsuffix.text + "_mat"
				sel[j].material.BumpMap.Normal_map.name = prefix.text + sel[i].name + 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 multiname CAN
addRollout zidingyi CAN
addRollout info CAN

对最初脚本的扩展完善版本,尝试了多卷展栏的形式来整合不同的模块。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值