----------------------------------------- --Power Masker Version 1.3 --Written by Dave Wortley ------------------------------------------ --Bug Fix: Set to 0 didn't do multisubs or VrayBlends. macroScript DWpowerMasker category:"DW Tools" toolTip:"Power Masker for Vray" ( try(destroydialog RL_MaterialEffectsIDAssigner)catch() GlobalInterface = (dotNetClass "Autodesk.Max.GlobalInterface") CreateStr = GlobalInterface.Instance.StringStream.Create global sceneMats = #() rollout RL_MaterialEffectsIDAssigner "Material Effects ID Assigner" width:180 ( listbox lbx_scenematerials "Scene Materials" height:20 spinner spn_ID "ID:" type:#integer range:[0,12800,0] checkbox chk_allMats "All Nested Mats" checked:true button btn_IDperSceneMat "ID per Material" width:160 tooltip:"Set a material effects ID per material in the scene materials library" button btn_MMEperMat "VRay MME per Material" width:160 tooltip:"Set a material effects ID per material and create VRay Multi-matte-element render elements for all materials automatically" button btn_MMEperLayer "VRay MME per Layer" width:160 tooltip:"Creates a VRay MME per layer in your scene, doesn't use Gbuffer IDs so you can still use these for randomness / Individual masks" button btn_allMattoZero "All Mat ID to Zero" width:160 tooltip:"Reset all material IDs to 0" button btn_refreshSceneMats "Refresh Scene Mats" width:160 tooltip:"Refresh the Material List (Sometimes you need to save you max scene for this to update properly)" button btn_deleteAllMMEs "Delete all MME Masks" width:160 tooltip:"Delete all MME Render Elements" button btn_help "Help" tooltip:"Help/About" width:160 label lbl_A "Written by David Wortley" label lbl_B "2016" hyperlink hyp_a "www.facebook.com/MaxMadeEasy" address:"https://www.facebook.com/MaxMadeEasy" offset:[-5,0] hyperlink hyp_b "davewortley.wordpress.com" address:"https://davewortley.wordpress.com" align:#center fn init = ( if not chk_allMats.checked then sceneMats = (for o in scenematerials where superclassof o == material and (refs.dependentnodes o).count != 0 collect o) else ( matTypes = (for o in material.classes where o.creatable == true collect o) sceneMats = #() for o in matTypes do ( --o != multimaterial and o!= VrayBlendMtl for mat in getclassinstances o where getNumSubMtls mat == 0 and (refs.dependentnodes mat).count != 0 do appendifunique sceneMats mat ) ) sceneMatsNames = #() for o in sceneMats do ( if finditem sceneMaterials o != 0 then ( append sceneMatsNames o.name ) else ( append sceneMatsNames (" - " + o.name) ) ) lbx_sceneMaterials.items = sceneMatsNames if sceneMats.count != 0 do spn_ID.value = (((GlobalInterface.Instance.ExecuteScript (CreateStr ("sceneMats[" + lbx_scenematerials.selection as string + "]")) true).ToMtlbase).GbufID) ) on RL_MaterialEffectsIDAssigner open do ( init() ) on chk_allMats changed state do init() on lbx_sceneMaterials selected sel do ( spn_ID.value = (((GlobalInterface.Instance.ExecuteScript (CreateStr ("sceneMats[" + lbx_scenematerials.selection as string + "]")) true).ToMtlbase).GbufID) ) on lbx_sceneMaterials doubleClicked sel do ( if keyboard.controlPressed then ( meditmaterials[1] = sceneMats[lbx_sceneMaterials.selection] ) else ( select (refs.dependentNodes scenemats[lbx_sceneMaterials.selection]) ) ) on spn_ID changed val do ( if sceneMats.count != 0 do ((GlobalInterface.Instance.ExecuteScript (CreateStr ("sceneMats[" + lbx_scenematerials.selection as string + "]")) true).ToMtlbase).GbufID = val ) on btn_IDperSceneMat pressed do ( for i = 1 to sceneMats.count do ( ((GlobalInterface.Instance.ExecuteScript (CreateStr ("sceneMats[" + i as string + "]")) true).ToMtlbase).GbufID = i ) if sceneMats.count != 0 do spn_ID.value = (((GlobalInterface.Instance.ExecuteScript (CreateStr ("sceneMats[" + lbx_scenematerials.selection as string + "]")) true).ToMtlbase).GbufID) ) on btn_MMEperLayer pressed do ( for i = 1 to layermanager.count by 3 do ( re = maxOps.getcurrenderelementmgr() theElement = multimatteelement() theElement.MatID = false theElement.elementName = ("MME_layer_" + ((ceil (1.0 * i / 3)) as integer) as string) theElement.R_gbufID = 10000 theElement.R_gbufIDOn = false theElement.G_gbufID = 10000 theElement.G_gbufIDOn = false theElement.B_gbufID = 10000 theElement.B_gbufIDOn = false theElement.redListType = 1 theElement.greenListType = 1 theElement.blueListType = 1 layer = layermanager.getlayer (i - 1) redObjs = (for o in objects where o.layer == layer collect o) if redObjs.count != 0 do ( theElement.redList = redObjs theElement.R_gbufIDOn = true ) layer = layermanager.getlayer (i) if layer != undefined do ( greenobjs = (for o in objects where o.layer == layer collect o) if greenObjs.count != 0 do ( theElement.greenList = greenObjs theElement.G_gbufIDOn = true ) ) layer = layermanager.getlayer (i + 1) if layer != undefined do ( blueobjs = (for o in objects where o.layer == layer collect o) if blueObjs.count != 0 do ( theElement.blueList = blueObjs theElement.B_gbufIDOn = true ) ) re.addRenderElement theElement ) ) on btn_MMEperMat pressed do ( btn_IDperSceneMat.pressed() for i = 1 to sceneMats.count by 3 do ( re = maxOps.getcurrenderelementmgr() theElement = multimatteelement() theElement.MatID = true theElement.elementName = ("MME_" + ((ceil (1.0 * i / 3)) as integer) as string + "_") theElement.R_gbufID = i theElement.G_gbufID = i + 1 theElement.B_gbufID = i + 2 re.addRenderElement theElement ) ) on btn_alltoZero pressed do ( matTypes = (for o in material.classes where o.creatable == true collect o) sceneMats = #() for o in matTypes do ( for mat in getclassinstances o do appendifunique sceneMats mat ) for i = 1 to sceneMats.count do ( ((GlobalInterface.Instance.ExecuteScript (CreateStr ("sceneMats[" + i as string + "]")) true).ToMtlbase).GbufID = 0 ) if sceneMats.count != 0 do spn_ID.value = (((GlobalInterface.Instance.ExecuteScript (CreateStr ("sceneMats[" + lbx_scenematerials.selection as string + "]")) true).ToMtlbase).GbufID) init() ) on btn_deleteAllMMEs pressed do ( re = maxOps.getcurrenderelementmgr() for i = (re.NumRenderElements() - 1) to 0 by -1 do ( theElement = re.GetRenderElement i if classof theElement == MultimatteElement do ( re.RemoveRenderElement theElement ) ) ) on btn_refreshSceneMats pressed do ( init() ) on btn_help pressed do ( messageBox "The 3dsmax UI only allows you to set material effects ID up to 16 channels. The VRayMtl allows you to go beyond this using the effects ID override but other types of materials don't have any UI to adjust this. This tool using a backdoor into 3dsmax to set the effects ID beyond the 16 limit imposed by the UI. This means you can create masks for every material in your scene.\n\nUsing this tool you can either assign effects IDs by hand or just press to automatically create them and their mask render elements.\n\nYou can also make a Vray Multi-matte mask for each layer in the scene too, this uses the include/exclude lists rather than the GBuffferIds, so that you can therefore use the GBuffer IDs for doing variation with texture maps or mask objects individually if you want to." title:"Help" beep:false ) ) CreateDialog RL_MaterialEffectsIDAssigner style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox, #style_resizing) )