def create_node(self, index): newNode = hou.node('/obj').createNode('null', "Node") specColor = colors[index] newNode.setColor(specColor) # Unique name arg enabled to prevent same name errors. newNode.setName(self.le.text(), unique_name=True) # Verify node is placed in new position each time to prevent overlaps. toolutils.moveNodesToGoodPosition([newNode])
def resizeFluidToMatchSops(fluidnode, matchobject): """ Resizes the fluid dynamic object fluidobject according to match object. """ dopnet = doptoolutils.getCurrentDopNetwork() movenodes = [] fluidtype = doptoolutils.nodeFluidType(fluidnode) solvernode = doptoolutils.nodeFluidSolverNode(fluidnode) merge = doptoolutils.findOrCreateNamedMerge(solvernode, 'post') resize = toolutils.findInputNodeOfType(merge, "gasresizefluid") if resize is None: resize = dopnet.createNode("gasresizefluid", "resizefluid") movenodes.append(resize) merge.setNextInput(resize) # Have resize link to the original smoke object to # make it more straightforward to delete. for channame in [ "tx", "ty", "tz", "sizex", "sizey", "sizez" ]: resize.parm(channame).set(fluidnode.parm(channame)) # Instrument our resize.. if fluidtype.startswith('upres'): fluidtype = fluidtype[len('upres'):] if fluidtype == 'pyro': fluidtype = 'smoke' # Set gasresizefluid parameters resize.parm("fluidtype").set(fluidtype) resize.parm("refobject").set("") resize.parm("reffield").set("") resize.parm("refobjpath").set(matchobject.path()+"/OUT") toolutils.moveNodesToGoodPosition(movenodes) return resize
def pImportAbcWithTextures(): # global vars stat_newshader = 0 movenodes = [] is_first = True shader = None abc_root = None # select Alembic archive # try: start_dir = os.environ["ASSETS"]+"/model/" except KeyError: start_dir = "/mnt/karramba/" hou.ui.setStatusMessage("Select Alembic file.") abc_file_name = hou.ui.selectFile(start_directory=start_dir, title="Choose Alembic", pattern="*.abc") if abc_file_name == "": print "No .abc file selected." return None # full alembic file path abc_file_name = os.path.expandvars(abc_file_name) abc_names = abc_file_name.split("/") # alembic file name abc_name = abc_names[len(abc_names)-1] # XML stuff # hou.ui.setStatusMessage("Choose XML file to import textures from.") xml_file_name = hou.ui.selectFile(start_directory=os.path.dirname(abc_file_name), title="Choose XML file with the textures data", pattern="*.xml") if xml_file_name == "": return None xml_file_name = os.path.expandvars(xml_file_name) xml = parse(xml_file_name) xmlobjects = xml.getElementsByTagName("object") # choose the mode to create materials mode = hou.ui.selectFromList(choices=("One material, local parameters", "Material for each object"), default_choices=(), exclusive=True, message="How to create materials?")[0] # parse objects from xml # for obj in xmlobjects: object_name = obj.getElementsByTagName("object_name")[0] object_path = object_name.childNodes[0].data object_path = object_path.replace('|', '/') # get texture data from XML object_texture_color = obj.getElementsByTagName("texture_color")[0] if object_texture_color.childNodes.length != 0: texture_path_color = object_texture_color.childNodes[0].data if texture_path_color == " ": texture_path_color = "" else: texture_path_color = "" object_texture_spec = obj.getElementsByTagName("texture_spec")[0] if object_texture_spec.childNodes.length != 0: texture_path_spec = object_texture_spec.childNodes[0].data if texture_path_spec == " ": texture_path_spec = "" else: texture_path_spec = "" object_texture_bump = obj.getElementsByTagName("texture_bump")[0] if object_texture_bump.childNodes.length != 0: texture_path_bump = object_texture_bump.childNodes[0].data if texture_path_bump == " ": texture_path_bump = "" #print "texture_path_bump: " + texture_path_bump else: texture_path_bump = "" # create root subnet nodes = object_path.split("/") compound_path = "" if abc_root is None: abc_root = hou.node("/obj").createNode("subnet", abc_name) abc_name = abc_root.name() try: abc_root_parms = abc_root.parmTemplateGroup() abc_root_parms.insertBefore(abc_root_parms.findFolder("Transform"), hou.StringParmTemplate("abc_file_name", "Abc File Name", num_components=1, string_type=hou.stringParmType.FileReference, help="Path to the Alembic archive (.abc) file.")) abc_root.setParmTemplateGroup(abc_root_parms) abc_root.parm("abc_file_name").set(str(abc_file_name)) except: pass # create subnets temp_root = abc_root for i in range(1, len(nodes)-2): compound_path += "/" + str(nodes[i]) #print "/obj/" + abc_name + compound_path if hou.node("/obj/" + abc_name + compound_path) is None: temp_root = temp_root.createNode("subnet", str(nodes[i])) movenodes.append(temp_root) else: temp_root = hou.node("/obj/" + abc_name + compound_path) # create geometry nodes i = len(nodes)-2 object_short_name = str(nodes[i]) #print "path: " + str(temp_root) print "geo: " + object_short_name geometry = temp_root.createNode("geo", object_short_name) geometry.children()[0].destroy() alembic = geometry.createNode("alembic", str(nodes[i])) alembic.setParmExpressions({"fileName": "chs(\"" + alembic.relativePathTo(abc_root) + "/abc_file_name\")"}) alembic.parm("objectPath").set(compound_path + "/" + str(nodes[i])) alembic.parm("groupnames").set("xform") movenodes.append(geometry) toolutils.moveNodesToGoodPosition(movenodes) # create materials # create one material and local parameters on each object if mode==0: # local vars if is_first: shader_template = hou.galleries.galleryEntries("mantrasurface")[0] shader = shader_template.createChildNode(hou.node("shop")) shader.setName(abc_name, True) stat_newshader += 1 is_first = False # assign material geometry.parm("shop_materialpath").set(shader.path()) # create local material parameters applyLocalOverrides(geometry) # assign textures, enable maps where needed if geometry.parm("baseColorMap") is not None: if texture_path_color != "": geometry.parm("baseColorMap").set(str(texture_path_color)) geometry.parm("useColorMap").set(1) if geometry.parm("specMap1") is not None: if texture_path_spec != "": geometry.parm("specMap1").set(str(texture_path_spec)) geometry.parm("useSpecMap1").set(1) if geometry.parm("displacementMap") is not None: if texture_path_bump != "": geometry.parm("displacementMap").set(str(texture_path_bump)) # geometry.parm("enableDispMap").set(1) # delete ogl_envmap if geometry.parm("ogl_envmap") is not None: geometry.parm("ogl_envmap").set("") # create a material for each object if mode==1: shader_template = hou.galleries.galleryEntries("mantrasurface")[0] shader = shader_template.createChildNode(hou.node("shop")) shader.setName(object_short_name, True) stat_newshader += 1 # assign textures if shader.parm("baseColorMap") is not None: if texture_path_color != "": shader.parm("baseColorMap").set(str(texture_path_color)) shader.parm("useColorMap").set(1) if shader.parm("specMap1") is not None: if texture_path_spec != "": shader.parm("specMap1").set(str(texture_path_spec)) shader.parm("useSpecMap1").set(1) if shader.parm("displacementMap") is not None: if texture_path_bump != "": shader.parm("displacementMap").set(str(texture_path_bump)) # shader.parm("enableDispMap").set(1) # assign material geometry.parm("shop_materialpath").set(shader.path()) print str(stat_newshader) + " shaders created."
def pImportAbcWithTextures(): # global vars stat_newshader = 0 movenodes = [] is_first = True shader = None abc_root = None # select Alembic archive # try: start_dir = os.environ["ASSETS"] + "/model/" except KeyError: start_dir = "/mnt/karramba/" hou.ui.setStatusMessage("Select Alembic file.") abc_file_name = hou.ui.selectFile(start_directory=start_dir, title="Choose Alembic", pattern="*.abc") if abc_file_name == "": print "No .abc file selected." return None # full alembic file path abc_file_name = os.path.expandvars(abc_file_name) abc_names = abc_file_name.split("/") # alembic file name abc_name = abc_names[len(abc_names) - 1] # XML stuff # hou.ui.setStatusMessage("Choose XML file to import textures from.") xml_file_name = hou.ui.selectFile( start_directory=os.path.dirname(abc_file_name), title="Choose XML file with the textures data", pattern="*.xml") if xml_file_name == "": return None xml_file_name = os.path.expandvars(xml_file_name) xml = parse(xml_file_name) xmlobjects = xml.getElementsByTagName("object") # choose the mode to create materials mode = hou.ui.selectFromList(choices=("One material, local parameters", "Material for each object"), default_choices=(), exclusive=True, message="How to create materials?")[0] # parse objects from xml # for obj in xmlobjects: object_name = obj.getElementsByTagName("object_name")[0] object_path = object_name.childNodes[0].data object_path = object_path.replace('|', '/') # get texture data from XML object_texture_color = obj.getElementsByTagName("texture_color")[0] if object_texture_color.childNodes.length != 0: texture_path_color = object_texture_color.childNodes[0].data if texture_path_color == " ": texture_path_color = "" else: texture_path_color = "" object_texture_spec = obj.getElementsByTagName("texture_spec")[0] if object_texture_spec.childNodes.length != 0: texture_path_spec = object_texture_spec.childNodes[0].data if texture_path_spec == " ": texture_path_spec = "" else: texture_path_spec = "" object_texture_bump = obj.getElementsByTagName("texture_bump")[0] if object_texture_bump.childNodes.length != 0: texture_path_bump = object_texture_bump.childNodes[0].data if texture_path_bump == " ": texture_path_bump = "" #print "texture_path_bump: " + texture_path_bump else: texture_path_bump = "" # create root subnet nodes = object_path.split("/") compound_path = "" if abc_root is None: abc_root = hou.node("/obj").createNode("subnet", abc_name) abc_name = abc_root.name() try: abc_root_parms = abc_root.parmTemplateGroup() abc_root_parms.insertBefore( abc_root_parms.findFolder("Transform"), hou.StringParmTemplate( "abc_file_name", "Abc File Name", num_components=1, string_type=hou.stringParmType.FileReference, help="Path to the Alembic archive (.abc) file.")) abc_root.setParmTemplateGroup(abc_root_parms) abc_root.parm("abc_file_name").set(str(abc_file_name)) except: pass # create subnets temp_root = abc_root for i in range(1, len(nodes) - 2): compound_path += "/" + str(nodes[i]) #print "/obj/" + abc_name + compound_path if hou.node("/obj/" + abc_name + compound_path) is None: temp_root = temp_root.createNode("subnet", str(nodes[i])) movenodes.append(temp_root) else: temp_root = hou.node("/obj/" + abc_name + compound_path) # create geometry nodes i = len(nodes) - 2 object_short_name = str(nodes[i]) #print "path: " + str(temp_root) print "geo: " + object_short_name geometry = temp_root.createNode("geo", object_short_name) geometry.children()[0].destroy() alembic = geometry.createNode("alembic", str(nodes[i])) alembic.setParmExpressions({ "fileName": "chs(\"" + alembic.relativePathTo(abc_root) + "/abc_file_name\")" }) alembic.parm("objectPath").set(compound_path + "/" + str(nodes[i])) alembic.parm("groupnames").set("xform") movenodes.append(geometry) toolutils.moveNodesToGoodPosition(movenodes) # create materials # create one material and local parameters on each object if mode == 0: # local vars if is_first: shader_template = hou.galleries.galleryEntries( "mantrasurface")[0] shader = shader_template.createChildNode(hou.node("shop")) shader.setName(abc_name, True) stat_newshader += 1 is_first = False # assign material geometry.parm("shop_materialpath").set(shader.path()) # create local material parameters applyLocalOverrides(geometry) # assign textures, enable maps where needed if geometry.parm("baseColorMap") is not None: if texture_path_color != "": geometry.parm("baseColorMap").set(str(texture_path_color)) geometry.parm("useColorMap").set(1) if geometry.parm("specMap1") is not None: if texture_path_spec != "": geometry.parm("specMap1").set(str(texture_path_spec)) geometry.parm("useSpecMap1").set(1) if geometry.parm("displacementMap") is not None: if texture_path_bump != "": geometry.parm("displacementMap").set( str(texture_path_bump)) # geometry.parm("enableDispMap").set(1) # delete ogl_envmap if geometry.parm("ogl_envmap") is not None: geometry.parm("ogl_envmap").set("") # create a material for each object if mode == 1: shader_template = hou.galleries.galleryEntries("mantrasurface")[0] shader = shader_template.createChildNode(hou.node("shop")) shader.setName(object_short_name, True) stat_newshader += 1 # assign textures if shader.parm("baseColorMap") is not None: if texture_path_color != "": shader.parm("baseColorMap").set(str(texture_path_color)) shader.parm("useColorMap").set(1) if shader.parm("specMap1") is not None: if texture_path_spec != "": shader.parm("specMap1").set(str(texture_path_spec)) shader.parm("useSpecMap1").set(1) if shader.parm("displacementMap") is not None: if texture_path_bump != "": shader.parm("displacementMap").set(str(texture_path_bump)) # shader.parm("enableDispMap").set(1) # assign material geometry.parm("shop_materialpath").set(shader.path()) print str(stat_newshader) + " shaders created."