def initProgressWindow(self): self.MayaGUIMode = OpenMaya.MGlobal.mayaState() == OpenMaya.MGlobal.kInteractive if self.MayaGUIMode: self.mProgress = OpenMayaUI.MProgressWindow() else: self.mProgress = consoleProgress()
def doIt(self, args): """ Class entry point. Starts the frame export process. """ if OpenMaya.MGlobal.mayaState() == OpenMaya.MGlobal.kInteractive: self.mProgress = OpenMayaUI.MProgressWindow() else: self.mProgress = consoleProgress() # check args length if (args.length() < 5): OpenMaya.MGlobal.displayError( "5 arguments are required for luxexport:\nfilename, imagename, width, height, cameraname\nA sixth option debug is optional" ) return # parse args into strings sceneFileName = args.asString(0) self.dprint("Outputfile: " + sceneFileName) imagefile = args.asString(1) self.dprint("Imagefile: " + imagefile) width = args.asInt(2) self.dprint("width: " + str(width)) height = args.asInt(3) self.dprint("height: " + str(height)) cameraName = args.asString(4) self.dprint("CameraName: " + cameraName) if (args.length == 6): debugMode = args.asInt(5) if debugMode == 1: self.debug = True self.dprint("Debug logging ON") self.log("Starting Lux export:") # init output stream/files sceneFilePathParts = sceneFileName.split(os.altsep) sceneFileName = sceneFilePathParts.pop() materialFileName = sceneFileName.replace(".lxs", ".lxm") meshFileName = sceneFileName.replace(".lxs", ".mesh.lxo") nurbsFileName = sceneFileName.replace(".lxs", ".nurbs.lxo") subdivFileName = sceneFileName.replace(".lxs", ".subdiv.lxo") volumeFileName = sceneFileName.replace(".lxs", ".volume.lxo") portalsMeshFileName = sceneFileName.replace(".lxs", ".mesh.portals.lxo") portalsNurbsFileName = sceneFileName.replace(".lxs", ".nurbs.portals.lxo") #portalsSubdivFileName = sceneFileName.replace(".lxs", ".subdiv.portals.lxo") sceneFilePath = os.altsep.join(sceneFilePathParts) + os.altsep if not self.debug: try: self.sceneFileHandle = open(sceneFilePath + sceneFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open files for writing\n") raise # self.log("Files opened") # # WRITE EXTERNAL FILES # # POLYGON MESHES if cmds.getAttr('lux_settings.scene_export_meshes') == 1: if not self.debug: try: self.meshFileHandle = open(sceneFilePath + meshFileName, "wb") self.portalsMeshFileHandle = open( sceneFilePath + portalsMeshFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open files for writing\n") raise # loop through meshes self.exportType(OpenMaya.MFn.kMesh, LuxModuleMeshOpt.MeshOpt, "Mesh", (self.meshFileHandle, self.portalsMeshFileHandle)) if not self.debug: self.meshFileHandle.close() self.portalsMeshFileHandle.close() # NURBS SURFACES if cmds.getAttr('lux_settings.scene_export_nurbs') == 1: if not self.debug: try: self.nurbsFileHandle = open(sceneFilePath + nurbsFileName, "wb") self.portalsNurbsFileHandle = open( sceneFilePath + portalsNurbsFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open files for writing\n") raise # loop through NURBS surfaces self.exportType( OpenMaya.MFn.kNurbsSurface, LuxModuleNurbs.Nurbs, "NURBS", (self.nurbsFileHandle, self.portalsNurbsFileHandle)) if not self.debug: self.nurbsFileHandle.close() self.portalsNurbsFileHandle.close() # SUBDIVS if cmds.getAttr('lux_settings.scene_export_subdivs') == 1: if not self.debug: try: self.subdivFileHandle = open( sceneFilePath + subdivFileName, "wb") self.portalsSubdivFileHandle = None # open(sceneFilePath + portalsMeshFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open files for writing\n") raise # loop through subdivs self.exportType( OpenMaya.MFn.kSubdiv, LuxModuleSubdiv.Subdiv, "Subdiv", (self.subdivFileHandle, self.portalsSubdivFileHandle)) if not self.debug: self.subdivFileHandle.close() #self.portalsSubdivFileHandle.close() # FLUID VOLUMES if cmds.getAttr('lux_settings.scene_export_volumes') == 1: if not self.debug: try: self.volumeFileHandle = open( sceneFilePath + volumeFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open files for writing\n") raise # loop through Fluid volumes self.exportType(OpenMaya.MFn.kFluid, LuxModuleVolume.Volume, "Fluid", self.volumeFileHandle) if not self.debug: self.volumeFileHandle.close() # MATERIALS if cmds.getAttr('lux_settings.scene_export_materials') == 1: if not self.debug: try: self.materialFileHandle = open( sceneFilePath + materialFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open files for writing\n") raise # loop through materials self.log("Exporting materials...") # TODO would be nice if this used the same exportType as everything else. itDn = OpenMaya.MItDependencyNodes(OpenMaya.MFn.kDependencyNode) while not itDn.isDone(): theNode = OpenMaya.MFnDependencyNode(itDn.thisNode()) expModule = LuxModuleMaterial.Material.MaterialFactory(theNode) if expModule != False: expOut = expModule.loadModule() self.dprint("Found Material: ") self.dprint(expOut) self.dprint("------------") if not self.debug: expModule.writeTo(self.materialFileHandle) itDn.next() self.log("...done") if not self.debug: self.materialFileHandle.close() # # END EXTERNAL FILES # # output render settings rs = LuxModuleRendersettings.Rendersettings( volumeFile=(sceneFilePath + volumeFileName)) rsOut = rs.loadModule() self.dprint('Rendersettings code: ') self.dprint(rsOut) self.dprint("-------------") if not self.debug: rs.writeTo(self.sceneFileHandle) self.log("Render settings written") # film output settings film = LuxModuleFilm.Film(width, height, imagefile) filmOut = film.loadModule() self.dprint('Film code: ') self.dprint(filmOut) self.dprint("-------------") if not self.debug: film.writeTo(self.sceneFileHandle) self.log("Film settings written") # Output the specified camera. found = False cameraItDag = OpenMaya.MItDag(OpenMaya.MItDag.kDepthFirst, OpenMaya.MFn.kCamera) cameraPath = OpenMaya.MDagPath() while not (cameraItDag.isDone() or found): cameraItDag.getPath(self.tempDagPath) currCamName = OpenMaya.MFnDagNode( self.tempDagPath.transform()).partialPathName() if ((currCamName == cameraName) or (cameraName == self.tempDagPath.partialPathName())): found = True cameraPath = self.tempDagPath #end if cameraItDag.next() #end while if not found: OpenMaya.MGlobal.displayError("Could not find the camera") return else: self.dprint("Found camera: " + currCamName) # obtain camera settings and write to file cam = LuxModuleCamera.Camera(cameraPath, width, height) camOut = cam.loadModule() self.dprint("Camera code: ") self.dprint(camOut) self.dprint("-------------") if not self.debug: cam.writeTo(self.sceneFileHandle) self.sceneFileHandle.write(os.linesep + 'WorldBegin' + os.linesep + os.linesep) self.log("Camera written") # WRITE INCLUDES IF EXTERNAL FILES EXIST for includeFile in [ materialFileName, meshFileName, nurbsFileName, subdivFileName, volumeFileName ]: if os.path.exists(sceneFilePath + includeFile): self.sceneFileHandle.write('Include "' + includeFile + '"' + os.linesep) # loop though lights self.exportType(OpenMaya.MFn.kLight, LuxModuleLight.Light.LightFactory, "Light") # find external PLY meshes via luxObjectLocators # find environment light via luxEnvironmentLight # find sunsky via luxSunsky self.log("Finding external meshes...") itDn = OpenMaya.MItDag(OpenMaya.MItDag.kDepthFirst, OpenMaya.MFn.kDependencyNode) while not itDn.isDone(): # theNode = OpenMaya.MFnDependencyNode( itDn.thisNode() ) itDn.getPath(self.tempDagPath) expModule = LuxModuleMiscNodes.MiscNodes.MiscNodeFactory( self.tempDagPath, [ sceneFilePath + portalsMeshFileName, sceneFilePath + portalsNurbsFileName ]) if expModule != False: expOut = expModule.loadModule() self.dprint("Found External Mesh: ") self.dprint(expOut) self.dprint("------------") if not self.debug: expModule.writeTo(self.sceneFileHandle) itDn.next() self.log("...done") # finish off the file self.log("Closing files") if not self.debug: self.sceneFileHandle.write(os.linesep + 'WorldEnd') self.sceneFileHandle.close() self.log("Export complete")
def meshToJointArray(mesh, parent=None, compIndexList=None): '''Create joint for every vertex on mesh''' # sanity check if not dp.objExists(mesh): sys.stderr.write('! meshToJointArray() -> input %s not found, aborting\n'%unicode(mesh)) return mesh, shape = dp.DependNode(mesh).filterTransformAndShape() if not (shape and shape.asMObject().hasFn(OpenMaya.MFn.kMesh)): sys.stderr.write('! meshToJointArray() -> invalid shape, aborting\n') return if parent: if dp.objExists(parent): parent = dp.DependNode(parent) else: sys.stdout.write('#* meshToJointArray() -> parent %s not found, setting to None\n'%unicode(parent)) parent = None # load plugin checkFunctions.loadPlugin('rigSkinClusterDq') # create arrayGeoConstraint arrayGeoCst = nameFunctions.changeType(mesh.name(), 'agc') if not dp.objExists(arrayGeoCst): arrayGeoCst = dp.createNode('arrayGeoConstraint', n=arrayGeoCst) shape.connect(arrayGeoCst, 'worldMesh', 'inMesh') arrayGeoCst.setAttr('constraintMode', 1) arrayGeoCst.setAttr('OutputMode', 1) else: arrayGeoCst = dp.DependNode(arrayGeoCst) # parent case decompose matrix if parent: dmx = nameFunctions.changeType(mesh.name(), 'dmx').split(':')[-1] dmx = dp.createNode('decomposeMatrix', n=dmx) parent.connect(dmx, 'worldMatrix', 'inputMatrix') # define array size vtxCount = shape.asMItGeometry().count() indexList = compIndexList if not compIndexList: indexList = range(vtxCount) else: vtxCount = len(indexList) # init progress window pWin = OpenMayaUI.MProgressWindow() pWinState = pWin.reserve() if pWinState: pWin.startProgress() pWin.setTitle('Processing %s to joints'%shape.name()) pWin.setProgressRange( 0, vtxCount ) # parse vtx baseJntName = nameFunctions.changeType(mesh.name(), 'jnt').split(':')[-1] jointList = dp.DependNodeArray() arrayIndex = arrayGeoCst.getAttr('uValue', size=True) for i in indexList: # update feedback ui if pWinState: pWin.setProgressStatus( 'processing component %d (%d/%d)'%(i, arrayIndex, vtxCount)) pWin.advanceProgress( 1 ) # get cv coordinates cvPos = dp.xform('%s.vtx[%d]'%(shape, i), q=True, t=True, ws=True) # set geoCosntraint values u,v = getClosestUVValuesOnMesh(shape, cvPos, offset=True) if not ( (0<u<1) and (0<v<1) ): sys.stdout.write('#* meshToJointArray() -> invalid u/v for component %d of %s, clamping\n'%(i, shape.name())) u = max(0.001, min(u, 1)) v = max(0.001, min(v, 1)) arrayGeoCst.setAttr('uValue[%d]'%arrayIndex, u, l=True) arrayGeoCst.setAttr('vValue[%d]'%arrayIndex, v, l=True) # create joint jnt = nameFunctions.addDescriptionToName(baseJntName, unicode(i).zfill(len(unicode(vtxCount)))) jnt = dp.createNode('joint', n=jnt, p=parent) jointList.append(jnt) # connect joint multMat = nameFunctions.changeType(jnt.name(), 'mm') multMat = dp.createNode('multMatrix', n=multMat) arrayGeoCst.connect(multMat, 'outMatrices[%d]'%arrayIndex, 'matrixIn[0]') jnt.connect(multMat, 'parentInverseMatrix', 'matrixIn[1]') decompMat = nameFunctions.changeType(jnt.name(), 'dm') decompMat = dp.createNode('decomposeMatrix', n=decompMat) multMat.connect(decompMat, 'matrixSum', 'inputMatrix') decompMat.connect(jnt, 'outputTranslate', 't') decompMat.connect(jnt, 'outputRotate', 'r') # if not parent: # arrayGeoCst.connect(jnt, 'outTranslate[%d]'%arrayIndex, 't') # else: # # create pointMatrixMult # pmm = nameFunctions.changeType(jnt.name(), 'pmm') # pmm = dp.createNode('pointMatrixMult', n=pmm) # # arrayGeoCst.connect(pmm, 'outTranslate[%d]'%arrayIndex, 'inPoint') # parent.connect(pmm, 'worldInverseMatrix', 'inMatrix') # # # connect to joint # pmm.connect(jnt, 'output', 't') # increment array index arrayIndex += 1 # end progress window if pWinState: pWin.endProgress() return jointList
def doIt(self): """ Class entry point. Starts the frame export process. """ if OpenMaya.MGlobal.mayaState() == OpenMaya.MGlobal.kInteractive: self.mProgress = OpenMayaUI.MProgressWindow() else: self.mProgress = consoleProgress() self.log("Starting pbrt export:") if not self.debug: try: self.sceneFileHandle = open(self.sceneFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open files for writing\n" ) raise # # WRITE EXTERNAL FILES # includeFileList = [] self.sceneFileHandle.write( PBRTGlobals.RenderGlobals(self.renderWidth, self.renderHeight, self.imageSaveName).exportStr() ) # Output the specified camera. cameraPath = self.findRenderCamera() if not cameraPath: OpenMaya.MGlobal.displayError("Could not find the camera") return self.sceneFileHandle.write(PBRTCamera.Camera(cameraPath,self.renderWidth, self.renderHeight).exportStr() ) # obtain camera settings and write to file self.dprint( "Camera code: " ) self.dprint( self.renderCameraName ) self.dprint( "-------------" ) if not self.debug: self.sceneFileHandle.write( os.linesep + 'WorldBegin' + os.linesep + os.linesep ) self.log("Camera written") # POLYGON MESHES if cmds.getAttr( 'pbrt_settings.scene_export_meshes' ) == 1: try: self.meshFileHandle = open(self.geoFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open file %s for writing\n"%self.geoFileName ) raise else: self.meshFileHandle = 0 if cmds.getAttr( 'pbrt_settings.scene_export_arealights' ) == 1: try: self.areaLightsFileHandle = open(self.areaLightsFileName, "wb") except: OpenMaya.MGlobal.displayError( "Failed to open file %s for writing\n"%self.areaLightsFileName ) raise else: self.areaLightsFileHandle = 0 # loop through meshes areaLightsWereWritten = 0 self.exportType( OpenMaya.MFn.kMesh, PBRTMesh.MeshOpt.GeoFactory, "Mesh", (self.meshFileHandle, self.areaLightsFileHandle) ) if self.meshFileHandle: self.meshFileHandle.close() if self.areaLightsFileHandle: areaLightsWereWritten = self.areaLightsFileHandle.tell() self.areaLightsFileHandle.close() includeFileList.append(self.geoFileName) includeFileList.append(self.areaLightsFileName) # MATERIALS if cmds.getAttr( 'pbrt_settings.scene_export_materials' ) == 1: self.exportType( OpenMaya.MFn.kDependencyNode, PBRTMaterial.Material.MaterialFactory, "Material" ) # loop though lights if cmds.getAttr( 'pbrt_settings.scene_export_lights' ) == 1: exportedLights = self.exportType( OpenMaya.MFn.kLight, PBRTLight.Light.LightFactory, "Light" ) if 0==exportedLights \ and cmds.getAttr( 'pbrt_settings.scene_export_defaultLighting' ) == 1 \ and areaLightsWereWritten==0: self.sceneFileHandle.write( PBRTLight.Light.defaultLighting()) self.exportType( OpenMaya.MFn.kLocator, PBRTLocator.Locator.Factory, "Locator" ) # WRITE INCLUDES IF EXTERNAL FILES EXIST for includeFile in includeFileList: if os.path.exists(includeFile): self.sceneFileHandle.write( 'Include "' + includeFile + '"' + os.linesep ) self.sceneFileHandle.write(os.linesep) # finish off the file self.log("Closing files") if not self.debug: self.sceneFileHandle.write( os.linesep + 'WorldEnd' ) self.sceneFileHandle.close() self.log("Export complete") self.dprint("File written: %s"%self.sceneFileName)