def exportStaticAssmblyRefUSD(self,location,destination=None,postfix = None, force=False, ignore=[]): ''' export static(one frame) USD file from the location which build with Assembly Reference ''' # create a stage self.__create__(destination, postfix, force) if self.__exist__: Logging.scenegraphSeparater("USD file already exist!") return # create default location as USD Xform self.__defineUSDXformPrimByLoops__(location) self.__defineUSDDefaultSetting__(location) self.relocateWorldCenter() # list all children of the parent DAG node and create USD prim for dag_node in self.traverse(location, stuckAR=True): if dag_node in ignore: continue if self.isAssembleReference(dag_node): reference_path = self.__getStaticModPath__(dag_node) reference_path = self.useDefaultSearchPath(reference_path) self.__defineUSDReferencePrim__(dag_node, reference_path) else: self.__defineUSDXformPrim__(dag_node) # checkout if this prim has animation,if true, record it. if self.isDAGNodeBeMoved(dag_node): self.__defineStaticUSDPrimTransform__(dag_node) self.__save__() self.__clear__() layer = self.useCurrentFolderPath(self.__destination__) self.sublayers.append(layer) return layer
def open(self, file_path=None): self.argsChaser() Logging.scenegraphLogging("$ " + self.__args__["mayaFile"].split("/")[-1]) if not file_path: file_path = self.__args__["mayaFile"] cmds.file(file_path, o=True, f=True) return
def export(self): Logging.scenegraphLogging("Export: \n" + str(self.__args__)) if self.__args__["scn"]: self.exportStaticAssmblyRefUSD("|assets|scn") elif self.__args__["asb"]: self.exportStaticAssmblyRefUSD("|master") else: pass Logging.scenegraphLogging("Done: " + self.__args__["mayaFile"])
def expandAssemblyReferece(self, location_path="|assets|scn", ignore_list=None): if not ignore_list: ignore_list = self.__ignore__ assemblyRefereceNodes = [] # find out current assemblyReference node for node_name in cmds.listRelatives(location_path, allDescendents=True, fullPath=True): node = pm.PyNode(node_name) if node.type() == "assemblyReference": assemblyRefereceNodes.append(node) for ar_node in assemblyRefereceNodes: definition = ar_node.attr("definition").get() namespace = ar_node.attr("repNamespace").get() full_path = ar_node.fullPath() for rep in ar_node.getListRepresentations(): if rep.endswith(".ma") or rep.endswith(".mb"): maya_file = rep if rep.endswith(".locator"): locator_file = rep if rep.endswith(".proxy.abc") or rep.endswith(".abc"): gpucache_file = rep if not ar_node.name() in ignore_list and not ar_node.fullPath( ) in ignore_list: Logging.scenegraphLogging("Expand:" + ar_node.name()) if int(definition.find("/scn/")) < 0 and int( definition.find("/asb/")) < 0: # if assembly file references a prop file,we record it dag node full path self.__reference_file__.append(full_path) # if assembly file references a asb file,we would load the maya file it referenced else: self.__assembly_file__.append(definition) ar_node.setActive(maya_file) else: Logging.scenegraphLogging("@Ignore:" + ar_node.name()) self.expandAssemblyReferece(ar_node.fullPath(), ignore_list)
def exportStaticMayaRefUSD(self,location,destination=None, postfix = None, force=False, ignore=[]): ''' export static(one frame) USD file from the location which build with Maya Reference ''' self.__create__(destination, postfix, force) if self.__exist__: Logging.scenegraphSeparater("USD file already exist!") return # create default location as USD Xform self.__defineUSDXformPrimByLoops__(location) self.__defineUSDDefaultSetting__(location) node_list = self.staticMayaRelatives(location) for dag_node in node_list: maya_path = cmds.referenceQuery(dag_node,filename=1) reference_path = self.__getPathMayaRefUSDCache2__(dag_node) reference_path = self.useDefaultSearchPath(reference_path) self.__defineUSDReferencePrim__(dag_node, reference_path) self.__save__() self.__clear__() layer = self.useCurrentFolderPath(self.__destination__) self.sublayers.append(layer) return layer
def __save__(self): self.__stage__.GetRootLayer().Save() Logging.scenegraphLogging("LCA USD file Saving to: %s"%self.__destination__)
def genarate(self): # open maya file Logging.scenegraphStepper(1, 4, "Start to Open maya file") self.open() Logging.scenegraphLogging("Done,open maya file") # coolapse all assembly reference Logging.scenegraphStepper(2, 4, "Start to collapse assembly reference") self.collapseAssemblyReferece() Logging.scenegraphLogging("Done,collapse assembly reference") # expand all assembly reference Logging.scenegraphStepper(3, 4, "Start to expand assembly reference") self.expandAssemblyReferece() Logging.scenegraphLogging("Done,expand assembly reference") Logging.scenegraphStepper(4, 4, "Start to genarate scene USD file") chr_usd = self.exportStaticMayaRefUSD("|assets|chr", postfix=".chr", force=True) prp_usd = self.exportStaticMayaRefUSD("|assets|prp", postfix=".prp", force=True) scn_usd = self.exportStaticAssmblyRefUSD("|assets|scn", postfix=".scn", force=True) self.setDressing(postfix=".set", force=True) SGUSDExporter = os.path.join(SGUSD_ROOT_PATH, "..", "..", "bin", "SGUSDExporter") for node in self.__assembly_file__: if node.find("/scn/") >= 0 or node.find("/asb/") >= 0: ## remove /assembly_definition from maya_path true_node = self.getMayaWorkFilePath(node) command = SGUSDExporter + " -f " + true_node + " --asb" os.system(command) Logging.scenegraphLogging("Done,genarate scene USD file")
sys.path.append("/home/xukai/Git/git_repo/scenegraphUSD/python") from scenegraphUSD.Core import SGUSDExporter from scenegraphUSD.Producer import SGUSDMayaProducer from scenegraphUSD.Setting import * from scenegraphUSD import Logging from scenegraphUSD import XMLWork try: import maya.cmds as cmds import pymel.core as pm except ImportError: print "Can`t find maya.cmds" print "Can`t find pymel.core" if __name__ == "__main__": mayaProducer = SGUSDMayaProducer() Logging.scenegraphStepper(1, 4, "Start to Open maya file") mayaProducer.open() Logging.scenegraphLogging("Done,open maya file") # coolapse all assembly reference Logging.scenegraphStepper(2, 4, "Start to collapse assembly reference") mayaProducer.collapseAssemblyReferece() Logging.scenegraphLogging("Done,collapse assembly reference") # expand all assembly reference Logging.scenegraphStepper(3, 4, "Start to expand assembly reference") mayaProducer.expandAssemblyReferece() Logging.scenegraphLogging("Done,expand assembly reference") Logging.scenegraphStepper(4, 4, "Start to genarate scene XML file") XMLWork.genarateXML() Logging.scenegraphLogging("Done,genarate scene USD file")
def open(self, file_path=None): if not file_path: file_path = self.__args__["mayaFile"] Logging.scenegraphLogging("Open:" + file_path) cmds.file(file_path, o=True, f=True) return
self.__args__ = args print args return args def open(self, file_path=None): if not file_path: file_path = self.__args__["mayaFile"] Logging.scenegraphLogging("Open:" + file_path) cmds.file(file_path, o=True, f=True) return def export(self): Logging.scenegraphLogging("Export: \n" + str(self.__args__)) if self.__args__["scn"]: self.exportStaticAssmblyRefUSD("|assets|scn") elif self.__args__["asb"]: self.exportStaticAssmblyRefUSD("|master") else: pass Logging.scenegraphLogging("Done: " + self.__args__["mayaFile"]) if __name__ == "__main__": Utility.USDPluginLoading() mayaExporter = SGUSDMayaExporter() Logging.scenegraphLogging("chasing Args") mayaExporter.argsChaser() Logging.scenegraphLogging("open file") mayaExporter.open() Logging.scenegraphLogging("export usd") mayaExporter.export()