def create_render_pass(name): with Modifier() as mod: render_pass = mod.createnode(name, type='RenderPass') mod.connect(render_pass.Width, Document().ProjectWidth) mod.connect(render_pass.Height, Document().ProjectHeight) mod.connect(render_pass.AspectRatio, Document().ProjectAspectRatio) return render_pass
def build_path(file_ext='png'): # Get file name / path and job path render_path, render_path_local, job_path = get_paths() try: os.mkdir(render_path) os.mkdir(render_path_local) os.mkdir(job_path) except: print('the folder already exists') # create name for the turntable out_image_vars = 'out' + '_$04f.$x' out_image_name = render_path_local + '/' + out_image_vars print(out_image_name) rPass = None rPass = li.get_Rpass() with Modifier() as mod: rPass.FileName.set(out_image_name) rPass.DisplayDriver.set(file_ext)
def add_GRP(grp_name, parent=None): if grp_name not in get_all_nodes(): with Modifier() as mod: if parent: mod.createnode(grp_name, parent=parent) else: mod.createnode(grp_name) node = get_node_from_name(grp_name) return node
def create_new_aov(name, parent, plug=None): with Modifier() as mod: if name not in reference_asset.get_all_nodes(): aov = mod.createnode(name, type='LayerOut', parent=parent) else: aov = reference_asset.get_node_from_name(name) if plug: aov.PlugName.set(plug) return aov
def import_geo(reload=0): asset_list = get_asset_list() for imported_asset in asset_list: if imported_asset[0].stage == defaults._geo_: if imported_asset[1] not in get_all_nodes() and not reload: with Modifier() as mod: geo_GRP = add_GRP('GEOMETRY') refNode, topNodes = mod.createref(imported_asset[1], imported_asset[2], geo_GRP) elif imported_asset[1] in get_all_nodes() and reload: refNode = get_node_from_name(imported_asset[1]) refNode.ReferenceFileName.set(imported_asset[2])
def import_anim(reload=0): asset_list = get_asset_list() for imported_asset in asset_list: if imported_asset[0].stage == defaults._animation_: if imported_asset[1] not in get_all_nodes() and not reload: with Modifier() as mod: anim_GRP = add_GRP('ANIMATION') refNode, topNodes = mod.createref(imported_asset[1], imported_asset[2], anim_GRP) elif imported_asset[1] in get_all_nodes() and reload: refNode = get_node_from_name(imported_asset[1]) refNode.ReferenceFileName.set(imported_asset[2])
def seq(mode='farm', file_ext='exr', qual=-1): # Get file name / path and job path render_path, job_path = get_paths() # Versionning versions = os.listdir(render_path) if not versions: os.mkdir(render_path + '/V000') else: filevalue = versions[-1] indexing = filevalue.split('V') indexing = int(indexing[-1]) indexing += 1 indexing = padding_numbers.padder(indexing, pad) filevalue = 'V' + str(indexing) os.mkdir(render_path + '/' + filevalue) last_version = os.listdir(render_path) last_version = last_version[-1] render_path = render_path + '/' + last_version out_image_vars = 'out' + '$n_.$04f.$x' out_image_name = render_path + '/' + out_image_vars quality_settings = var_render + quality[qual] rPass = None rPass = li.get_Rpass() prefs = pynode('Preferences') with Modifier() as mod: prefs.RenderfarmSequence.set(quality_settings) rPass.FileName.set(out_image_name) rPass.DisplayDriver.set(file_ext) # Render the images opts = dict({'JobsDirectory': job_path}) guerilla.render(mode, opts)
def exrId(path, filename): ''' Transforms the Id pass into an exrid pass. This function also creates a folder Returns the final path for the exrId. Syntax : exrId(path=<render_path>, filename=<name_of_your_render_file>) example : new_path = exrId(path='D:\\Renders',filename='$o_ID.$f.x$') print(new_path) This prints ===> 'D:/Renders/exrid/$o_ID.$f.x$' ''' rLayer = pynode('RenderPass|Layer') with Modifier() as mod: id_aov = None for aov in rLayer.children(): if aov.PlugName.get() == 'Id': print('ID pass found.') id_pass = aov.PlugName.get() id_aov = aov else: raise ValueError('No Id Pass found.') if id_aov: id_aov.OverrideSettings.set(True) id_aov.FileName.set(aov_path) id_aov.DisplayDriver.set('exrid') path += '\\exrid' if os.path.exists(path): if len(os.listdir(path)) > 0: raise ValueError( 'This folder already exists and has objects in it.') print('The folder already exists but is empty.') else: os.mkdir(path) aov_path = path + '\\' + filename return aov_path
def import_grooming(reload=0): asset_list = get_asset_list() grooming_GRP = add_GRP('GROOMING') for imported_asset in asset_list: if imported_asset[0].stage == defaults._hair_: nodes_list = [] folder = os.path.split(imported_asset[2])[0] for file in os.listdir(folder): if file.endswith('.fur'): node_tuple = [ file.split('.')[-2], os.path.join(folder, file) ] nodes_list.append(node_tuple) if imported_asset[1] not in get_all_nodes() and not reload: for node_tuple in nodes_list: with Modifier() as mod: nspace_GRP = add_GRP(imported_asset[1], grooming_GRP) node_name = '{}:{}'.format(imported_asset[1], node_tuple[0]) yeti_node = mod.createnode(node_name, "Yeti", nspace_GRP) yeti_node.File.set(node_tuple[1]) yeti_node.HierarchyMode.set(2) yeti_node.Membership.set(node_tuple[0]) elif imported_asset[1] in get_all_nodes() and reload: for node_tuple in nodes_list: nspace_GRP = add_GRP(imported_asset[1], grooming_GRP) node_name = '{}:{}'.format(imported_asset[1], node_tuple[0]) yeti_node = get_node_from_name(node_name) yeti_node.File.set(node_tuple[1])
def create_GRP(grp_name): with Modifier() as mod: mod.createnode(grp_name)
def import_cfx(reload=0): asset_list = get_asset_list() grooming_GRP = add_GRP('CFX') for imported_asset in asset_list: fur_ext = prefs().custom_pub_ext_dic[defaults._cfx_][defaults._maya_] if fur_ext == 'fur': if imported_asset[0].stage == defaults._cfx_: nodes_list = [] folder = os.path.split(imported_asset[2])[0] for file in os.listdir(folder): if file.endswith('.fur'): file = file.replace( file.split('.')[-2] + '.fur', '%04d.fur') node_tuple = [ file.split('.')[-3], os.path.join(folder, file) ] if node_tuple not in nodes_list: nodes_list.append(node_tuple) if imported_asset[1] not in get_all_nodes() and not reload: for node_tuple in nodes_list: with Modifier() as mod: nspace_GRP = add_GRP(imported_asset[1], grooming_GRP) node_name = '{}:{}'.format(imported_asset[1], node_tuple[0]) yeti_node = mod.createnode(node_name, "Yeti", nspace_GRP) yeti_node.File.set(node_tuple[1]) yeti_node.HierarchyMode.set(2) yeti_node.Membership.set(node_tuple[0]) elif imported_asset[1] in get_all_nodes() and reload: for node_tuple in nodes_list: nspace_GRP = add_GRP(imported_asset[1], grooming_GRP) node_name = '{}:{}'.format(imported_asset[1], node_tuple[0]) yeti_node = get_node_from_name(node_name) yeti_node.File.set(node_tuple[1]) if fur_ext == "abc": if imported_asset[0].stage == defaults._cfx_: folder = os.path.split(imported_asset[2])[0] file = os.path.join(folder, os.listdir(folder)[0]) hair_tag = file.split('.')[-3] if imported_asset[1] not in get_all_nodes() and not reload: with Modifier() as mod: refNode, topNodes = mod.createref( imported_asset[1], file, grooming_GRP) refNode.Membership.set(hair_tag) refNode.Membership.set(hair_tag) elif imported_asset[1] in get_all_nodes() and reload: refNode = get_node_from_name(imported_asset[1]) refNode.ReferenceFileName.set(file)
def import_texturing(reload=0): asset_list = get_asset_list() for imported_asset in asset_list: if imported_asset[0].stage == defaults._texturing_: asset = asset_core.string_to_asset( os.environ[defaults._asset_var_]) shaders_GRP = add_GRP('SHADERS') if imported_asset[1] not in get_all_nodes(): rg = Node.create(imported_asset[1], 'RenderGraph') rg.move(shaders_GRP) tag1 = rg.loadfile('$(LIBRARY)/rendergraph/tag.gnode') tag1[0].Tag.set(asset.name) tag1[0].rename(asset.name) at1 = rg.loadfile('$(LIBRARY)/rendergraph/attributes.gnode') at1[0].overrideinheritedattr('RaytraceSubdivLevel', 2) at1[0].overrideinheritedattr('Subdiv', True) at1[0].Input1.Plug.connect(tag1[0].Output1.Plug) ds1 = rg.loadfile('$(LIBRARY)/rendergraph/shader.gnode' ) # Displacement Shader ds1[0].Shader.set('Displacement') ds1[0].Mode.set('displacement') ds1[0].rename('{}_displacement_shader'.format(asset.name)) ds1[0].Input1.Plug.connect(at1[0].Output1.Plug) sh1 = rg.loadfile( '$(LIBRARY)/rendergraph/shader.gnode') # Surface Shader sh1[0].Shader.set('Surface2') sh1[0].Mode.set('surface') sh1[0].rename('{}_main_shader'.format(asset.name)) sh1[0].Input1.Plug.connect(ds1[0].Output1.Plug) out1 = rg.loadfile('$(LIBRARY)/rendergraph/output.gnode') out1[0].Input1.Plug.connect(sh1[0].Output1.Plug) replace = 0 else: rg = get_node_from_name(imported_asset[1]) surface_node = get_node_from_name('{}_main_shader'.format( asset.name)) sh1 = [] sh1.append(surface_node) replace = 1 base_color_maps = [] metalness_maps = [] roughness_maps = [] normal_maps = [] sss_maps = [] height_maps = [] for texture_map in get_maps(imported_asset[2]): print(texture_map) udim = texture_map.split('.')[-2] texture_map = texture_map.replace(udim, '%04d') if 'BASECOLOR' in texture_map.upper(): base_color_maps.append(texture_map) if 'METALLIC' in texture_map.upper(): metalness_maps.append(texture_map) if 'ROUGHNESS' in texture_map.upper(): roughness_maps.append(texture_map) if 'NORMAL' in texture_map.upper(): normal_maps.append(texture_map) if 'SSS' in texture_map.upper(): sss_maps.append(texture_map) if 'HEIGHT' in texture_map.upper(): height_maps.append(texture_map) with Modifier() as mod: try: if base_color_maps != []: if not replace: attrSh1 = mod.createnode('DiffuseColor', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('Texture') p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) attrSh1.overrideinheritedattr("Gamma", "linear") else: p = sh1[0].DiffuseColor.File if replace and p.get() != '': p.set(base_color_maps[0]) elif not replace: p.set(base_color_maps[0]) else: logger.warning("No DiffuseColor to load") except: logger.error("Can't load DiffuseColor") try: if base_color_maps != [] and metalness_maps != [] and roughness_maps != []: if not replace: attrSh1 = mod.createnode('MetalColor', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('Texture') p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) attrSh1.overrideinheritedattr("Gamma", "linear") else: p = sh1[0].MetalColor.File if replace and p.get() != '': p.set(base_color_maps[0]) elif not replace: p.set(base_color_maps[0]) if not replace: attrSh1 = mod.createnode('Metal', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('MaskTexture') attrSh1.overrideinheritedattr("Gamma", "data") p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) else: p = sh1[0].Metal.File if replace and p.get() != '': p.set(metalness_maps[0]) elif not replace: p.set(metalness_maps[0]) if not replace: attrSh1 = mod.createnode('MetalRoughness', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('MaskTexture') attrSh1.overrideinheritedattr("Gamma", "data") p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) else: p = sh1[0].MetalRoughness.File if replace and p.get() != '': p.set(roughness_maps[0]) elif not replace: p.set(roughness_maps[0]) else: logger.warning("No Metallic to load") except: logger.error("Can't load Metallic") try: if roughness_maps != []: if not replace: sh1[0].overrideinheritedattr('Spec1', 1) attrSh1 = mod.createnode('Spec1Roughness', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('MaskTexture') attrSh1.overrideinheritedattr("Gamma", "data") p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) else: p = sh1[0].Spec1Roughness.File if replace and p.get() != '': p.set(roughness_maps[0]) elif not replace: p.set(roughness_maps[0]) else: logger.warning("No Roughness to load") except: logger.error("Can't load Roughness") try: if normal_maps != []: if not replace: attrSh1 = mod.createnode('Normal', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('NormalMap') p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) attrSh1.overrideinheritedattr("Gamma", "data") else: p = sh1[0].Normal.File if replace and p.get() != '': p.set(normal_maps[0]) elif not replace: p.set(normal_maps[0]) else: logger.warning("No Normal to load") except: logger.error("Can't load Normal") try: if sss_maps != []: if not replace: attrSh1 = mod.createnode('SSS', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('MaskTexture') attrSh1.overrideinheritedattr("Gamma", "data") p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) else: p = sh1[0].Shader.File if replace and p.get() != '': p.set(sss_maps[0]) elif not replace: p.set(sss_maps[0]) else: logger.warning("No sss to load") except: print(str(traceback.format_exc())) logger.error("Can't load sss") try: if height_maps != []: if not replace: attrDs1 = mod.createnode('Amount', type='AttributeShader', parent=ds1[0]) attrDs1.Shader.set('MaskTexture') attrDs1.overrideinheritedattr("Gamma", "data") ds1[0].overrideinheritedattr( 'Normalization', "Affine") ds1[0].overrideinheritedattr('Offset', 0) ds1[0].overrideinheritedattr( "RaytraceDisplacement", 0.02) ds1[0].overrideinheritedattr("DisplaceAmount", 1) ds1[0].State.set("bypass") p = attrDs1.createplug('File', 'user', 'texture', Plug.Dynamic) else: p = ds1[0].Shader.File if replace and p.get() != '': p.set(height_maps[0]) elif not replace: p.set(height_maps[0]) else: logger.warning("No height to load") except: print(str(traceback.format_exc())) logger.error("Can't load height")
def launch_new(mode='farm', file_ext='png', qual='LD_', local=False, frames=None, exrid=True): ''' ''' # Get file name / path and job path render_path, render_local_path, job_path = get_paths() #passer en mode hyperespace rPass = None rPass = li.get_Rpass() prefs = pynode('Preferences') # Versionning day, hour = format_time() folder = day + '_' + hour + '.' + mode.lower() render_path = render_path + '/' + folder os.system('setx IMAGES ' + render_path) out_image_vars = 'out' + '_$n_$04f.$x' try: os.mkdir(render_path) if exrid == True: #aov_path = exrId(render_path, out_image_vars) pass except: raise Exception('ARRETE TOI') out_image_name = render_path + '/' + out_image_vars out_pass_name = '$o' with Modifier() as mod: rPass.FileName.set(out_image_name) quality_settings = var_render + qual with Modifier() as mod: prefs.RenderfarmSequence.set(quality_settings) rPass.FileName.set(out_image_name) rPass.FileLayerName.set(out_pass_name) rPass.DisplayDriver.set(file_ext) # Job Path => temporary ? job_path = render_path + '/' + 'jobs' os.mkdir(job_path) if frames: opts = dict({ 'JobsDirectory': job_path, 'RibsDirectory': job_path, 'Frames': frames }) else: opts = dict({'JobsDirectory': job_path, 'RibsDirectory': job_path}) # Render the images guerilla.render(mode, opts) # revenir en mode local out_image_name = render_local_path + '/' + out_image_vars with Modifier() as mod: rPass.FileName.set(out_image_name)
def asset(mode='farm', file_ext='png', qual=1, local=False): ''' ''' # Get file name / path and job path render_path, render_local_path, job_path = get_paths() #passer en mode hyperespace rPass = None rPass = li.get_Rpass() prefs = pynode('Preferences') # Versionning versions = os.listdir(render_path) if 'local' in versions: versions.remove('local') if not versions: os.mkdir(render_path + '/V000') else: filevalue = versions[-1] indexing = filevalue.split('V') indexing = int(indexing[-1]) indexing += 1 indexing = padding_numbers.padder(indexing, pad) filevalue = 'V' + str(indexing) os.mkdir(render_path + '/' + filevalue) last_version = os.listdir(render_path) last_version = last_version[-1] render_path = render_path + '/' + last_version out_image_vars = 'out' + '_.$04f.$x' out_image_name = render_path + '/' + out_image_vars with Modifier() as mod: rPass.FileName.set(out_image_name) quality_settings = var_render + quality[qual] with Modifier() as mod: prefs.RenderfarmSequence.set(quality_settings) rPass.FileName.set(out_image_name) rPass.DisplayDriver.set(file_ext) # Job Path => temporary ? job_path = render_path + '/' + 'jobs' os.mkdir(job_path) opts = dict({'JobsDirectory': job_path}) # Render the images print('render place : ' + out_image_name) print('render jobs : ' + job_path) guerilla.render(mode, opts) # revenir en mode local out_image_name = render_local_path + '/' + out_image_vars print('new render place : ' + out_image_name) with Modifier() as mod: rPass.FileName.set(out_image_name)
def create_new_layer(name, parent): with Modifier() as mod: layer = mod.createnode(name, type='RenderLayer', parent=parent) return layer
def clear_rPasses(self): for renderpass in self.doc.children(type="RenderPass", recursive=True): with Modifier() as mod: mod.deletenode(renderpass)
# IMPORT ALEMBIC ASSEMBLY INTO GUERILLA from guerilla import Modifier, pynode with Modifier() as mod: assembly_path = 'D:\\travail\\supinfocom\\final\\pipe_tester\\liquefacteur\\temp\\test.abc' parent_name = 'shot_01' ref_name = 'test' parent_name = mod.createnode(parent_name, type = 'SceneGraphNode') refNode, topNodes = mod.createref(ref_name, assembly_path, parent_name, {'prefixnodes':False,'containschildren':False})
def delete_default_pass(): with Modifier() as mod: if 'RenderPass' in reference_asset.get_all_nodes(): mod.deletenode(reference_asset.get_node_from_name('RenderPass'))