Problem I’m solving
Converting Bitmaps to Vray Bitmaps to connect the VrayUVWRandomizer node to them is always a tedious task. Sometimes, that take away your focus on creating your amazing work.
Solution
This convenient script allows you to quickly and easily create a VrayBitmap node from a Bitmap and automatically attach a VrayUVWRandomizer node in just one click!
Installation
- Simply just drag the script to the viewport to install.
- Right-click on the toolbar > Customize…
- Choose the tab ‘Toolbars’
- In the Category: dropdown, select ‘ManniiCode’
- Drag the script to the toolbar where ever you want!
Videos
Code
from pymxs import runtime as rt #Define a MaterialObject class class MaterialObject: def __init__(self, name, node, pos): self.name = name self.node = node self.pos = pos #Define a function to get all the Slate Material Editor (SME) node def get_selected_SME_node(): #Get the SME view sme_active_view = rt.SME.GetView(rt.SME.activeView) num_nodes = sme_active_view.GetNumNodes() #List for selected material smeSelMats = [] sme_selected_node = sme_active_view.GetSelectedNodes() for i in range(0,num_nodes): material_node = rt.TrackViewNodes["sme"][sme_active_view.name][i].reference reference_node = sme_active_view.GetNodeByRef(material_node) if reference_node.selected and rt.classOf(material_node) == rt.Bitmaptexture: new_mat_obj = MaterialObject(material_node.name, material_node, reference_node.position) smeSelMats.append(new_mat_obj) return smeSelMats def get_randomizer_pos(mat_list): #Get average position for all nodes collect_point_x = [] collect_point_y = [] for obj in (mat_list): collect_point_x.append(obj.pos.x) collect_point_y.append(obj.pos.y) randomizer_coordinate = rt.Point2(min(collect_point_x)-500, sum(collect_point_y)/len(collect_point_y)) return randomizer_coordinate def create_vray_bitmap_from_selected(mat_list, position): #create randomizer node uvw_rand = rt.VRayUVWRandomizer() for obj in (mat_list): #create VrayBitmap node new_mat = rt.vrayBitmap() new_mat.filename = obj.node.filename #Link Vray Bitmap to the Randomizer node new_mat.mapSource = uvw_rand #Get the position of the node and shift a bit for user hint sme_view_node = rt.sme.GetView(rt.sme.activeView) sme_view_node.CreateNode(new_mat,rt.Point2(obj.pos.x - 80, obj.pos.y - 80)) #Replace the node rt.replaceInstances(obj.node,new_mat) #move it into position uvw_rand_node = rt.SME.GetView(rt.SME.activeView).GetNodeByRef(uvw_rand) uvw_rand_node.position = position #Filter selected node filter_selected = rt.SME.GetView(rt.SME.activeView).GetSelectedNodes() node_check_list = [x.node.filename for x in mat_list] for i in filter_selected: if rt.classof(i.reference) != rt.VrayBitmap: i.selected = False rt.SME.GetView(rt.SME.activeView).DeleteSelection() rt.SME.open() selected_materials = get_selected_SME_node() if len(selected_materials) > 0: uv_randomizer_node = get_randomizer_pos(selected_materials) rd_position = get_randomizer_pos(selected_materials) create_vray_bitmap_from_selected(selected_materials, rd_position)