def exportRig(self): """ will export SH and Geo found in the geo folder """ # rig and geo should not be referenced # find SH, delete constraints, parent to world # find geo folder parent to world # select SH and geo folder and export as fbx to fbx folder pymelLogger.debug( 'Starting rig export' ) export = 0 for rig in self.rootList: if cmds.objExists(rig): # check if geo folder also exists if cmds.objExists(self.geo): self._delConstraints(rig) cmds.parent(rig, w=1) cmds.parent(self.geo, w=1) cmds.select(rig,self.geo, r=1) #print rig, self.geo if self._fbxExport( 2 ): cmds.confirmDialog(m='FBX Rig Exported', button='Ok') pymelLogger.debug( 'Finished rig export' ) export = 1 break else: pymelLogger.error( 'No geo folder has been found' ) if export == 0 : pymelLogger.error( 'No Rig Exported. Note: Referenced Rigs Will Not Export' )
def exportAsset(self, fileName=None, assetPath=None, unityPath=None, ignore=None): ''' Export Assets from a .ma animation file as .fbx. ''' pymelLogger.debug('exportAsset(): Starting...') exporter = Export.Export() if not os.path.isfile(fileName): msg = 'File does not exist: %s'%fileName pymelLogger.error(msg) raise Exception(msg) # Open the file pm.openFile(fileName, f=True) pymelLogger.debug('exportAsset(): Opened file: %s'%fileName) # Export the Asset results = None results = exporter.exportAsset(fileName=fileName, assetPath=assetPath, unityPath=unityPath, ignore=ignore) if not results: msg = 'exportAsset(): Nothing exported!' pymelLogger.error(msg) raise Exception(e) for each in results: pymelLogger.debug('Exported: %s'%os.path.basename(each)) pymelLogger.debug('exportAsset(): End.') return results
def exportAnim(self, fileName=None, assetPath=None, unityPath=None, ignore=None): ''' Export animation for each rig found in the current scene. Export camera with name from names.cameras.shot_cam_names list Rig must be referenced. ''' pymelLogger.debug('exportAnim(): Starting...') # Export to directory wih animation file name # Assets/art/animation/anim_type/anim_name try: fName = os.path.basename(fileName)[:-3] typ = fName.split('_')[-2:] typ = typ[0] + '_' + typ[1] dirName = fName.split('_')[:-2] dName = '' for each in dirName: dName += each + '_' dirName = dName[:-1] unityPath = unityPath + '/animation/' + typ + '/' + dirName except Exception, e: pymelLogger.error('exportAnim(): Error creating UnityPath.') pymelLogger.error(e) raise Exception(e)
def exportRig(self): """ will export SH and Geo found in the geo folder """ # rig and geo should not be referenced # find SH, delete constraints, parent to world # find geo folder parent to world # select SH and geo folder and export as fbx to fbx folder pymelLogger.debug('Starting rig export') export = 0 for rig in self.rootList: if cmds.objExists(rig): # check if geo folder also exists if cmds.objExists(self.geo): self._delConstraints(rig) cmds.parent(rig, w=1) cmds.parent(self.geo, w=1) cmds.select(rig, self.geo, r=1) #print rig, self.geo if self._fbxExport(2): cmds.confirmDialog(m='FBX Rig Exported', button='Ok') pymelLogger.debug('Finished rig export') export = 1 break else: pymelLogger.error('No geo folder has been found') if export == 0: pymelLogger.error( 'No Rig Exported. Note: Referenced Rigs Will Not Export')
class Export(object): def __init__(self): ''' Export asset/rig/animation/camera as FBX to AssetLib and Unity directory. ''' self.rootList = rig_names.rootList self.assetTypes = asset_names.types self.camNames = cam_names.shot_cam_names self.geo = 'geo' self.custom = 'custom' pymelLogger.debug('Initializing...') def exportAnim(self, fileName=None, assetPath=None, unityPath=None, ignore=None): ''' Export animation for each rig found in the current scene. Export camera with name from names.cameras.shot_cam_names list Rig must be referenced. ''' pymelLogger.debug('exportAnim(): Starting...') # Export to directory wih animation file name # Assets/art/animation/anim_type/anim_name try: fName = os.path.basename(fileName)[:-3] typ = fName.split('_')[-2:] typ = typ[0] + '_' + typ[1] dirName = fName.split('_')[:-2] dName = '' for each in dirName: dName += each + '_' dirName = dName[:-1] unityPath = unityPath + '/animation/' + typ + '/' + dirName except Exception, e: pymelLogger.error('exportAnim(): Error creating UnityPath.') pymelLogger.error(e) raise Exception(e) pymelLogger.debug('File name: %s' % fileName) pymelLogger.debug('Asset path: %s' % assetPath) pymelLogger.debug('Unity path: %s' % unityPath) # Make AssetLib fbx / Unity directories if they do not exist try: if not os.path.isdir(assetPath): os.makedirs(assetPath) if not os.path.isdir(unityPath): os.makedirs(unityPath) except Exception, e: pymelLogger.error('exportAnim(): Error creating directory.') pymelLogger.error(e) raise Exception(e)
def PRINT(msg='', item='', type='info'): printMsg = '|| %s || %s' %(msg.ljust(65), item.ljust(20)) if type == 'debug': pymelLogger.debug('\t\t\t%s'%printMsg) elif type == 'info': pymelLogger.info('\t\t\t%s'%printMsg) elif type == 'warning': pymelLogger.warning('\t%s'%printMsg) elif type == 'error': pymelLogger.error('\t%s'%printMsg) elif type == 'critical': pymelLogger.critical('\t%s'%printMsg) else: pymelLogger.error('Cannot Print Message: Invalid Type') return
def exportAnim(self, fileName=None, assetPath=None, unityPath=None, ignore=None): ''' Export rig and/or prop animation from a .ma animation file as .fbx. ''' pymelLogger.debug('exportAnim(): Starting...') exporter = Export.Export() #pdb.set_trace() if not os.path.isfile(fileName): msg = 'File does not exist: %s'%fileName pymelLogger.error(msg) raise Exception(msg) # Open the file pm.openFile(fileName, f=True) pymelLogger.debug('exportAnim(): Opened file: %s'%fileName) # Export the animation results = exporter.exportAnim(fileName=fileName, assetPath=assetPath, unityPath=unityPath, ignore=ignore) pymelLogger.debug('exportAnim(): End.') return results
def exportAnim( self, fileName=None, assetPath=None, unityPath=None, ignore=None ): ''' Export animation for each rig found in the current scene. Export camera with name from names.cameras.shot_cam_names list Rig must be referenced. ''' pymelLogger.debug('exportAnim(): Starting...') # Export to directory wih animation file name # Assets/art/animation/anim_type/anim_name try: fName = os.path.basename(fileName)[:-3] typ = fName.split('_')[-2:] typ = typ[0] + '_' + typ[1] dirName = fName.split('_')[:-2] dName = '' for each in dirName: dName += each + '_' dirName = dName[:-1] unityPath = unityPath + '/animation/' + typ + '/' + dirName except Exception,e: pymelLogger.error('exportAnim(): Error creating UnityPath.') pymelLogger.error(e) raise Exception(e)
def exportAsset(self, fileName=None, assetPath=None, unityPath=None, ignore=None): """ Export 'custom' group geo and SH skeleton. """ pymelLogger.debug('Starting: exportAsset()...') # Export to directories with type and asset file name print unityPath print assetPath found = False for typ in self.assetTypes: platform = sys.platform if 'win' in platform: #pathElems = assetPath.split(os.sep) pathElems = assetPath.split('/') else: if '/' in assetPath: pathElems = assetPath.split('/') else: pathElems = assetPath.split('\\') if typ in pathElems: pymelLogger.debug('exportAsset(): Type: %s' % typ) unityPath = unityPath + '/%s/' % typ + os.path.basename( assetPath[:-4]) found = True break if not found: msg = 'exportAsset(): Asset is not in a directory named after a type.' pymelLogger.error(msg) raise Exception(msg) pymelLogger.debug('File name: %s' % fileName) pymelLogger.debug('Asset path: %s' % assetPath) pymelLogger.debug('Unity path: %s' % unityPath) # Make AssetLib fbx / Unity directories if they do not exist try: if not os.path.isdir(assetPath): os.makedirs(assetPath) if not os.path.isdir(unityPath): os.makedirs(unityPath) except Exception, e: pymelLogger.error('exportAsset(): Error creating directory.') pymelLogger.error(e) raise Exception(e)
def build(self, *args): ''' Call methods to build the joints on nurbs plane setup ''' _name = 'build' pymelLogger.info('Started: %s' % _name) # Validate user input name = pm.textFieldGrp(self.nameFld, q=1, text=1) num = pm.intFieldGrp(self.numFld, q=1, v=1)[0] rad = pm.floatFieldGrp(self.radFld, q=1, v=1)[0] axis = pm.radioButtonGrp(self.buildFld, q=1, sl=1) objs = pm.ls(sl=1) if not name: pymelLogger.error('No name entered by user. Must enter a name. Exiting.') return if num < 1 or num > 50: pymelLogger.error('%s is an invalid value for number of joints. Must be between 3 - 50. Exiting.' % num) return if rad < 0.009 or rad > 10: pymelLogger.error('%s is an invalid value for joint radius. Must be between 0.01 - 10. Exiting.' % rad) return if not objs: pymelLogger.error('No objects selected. Must select objects to build curve along. Exiting.') return # Call build methods crv1, crv2 = self._createCurves(objs=objs, axis=axis, num=num) plane = self._createPlane(name=name, crv1=crv1, crv2=crv2) follicles = self._createFollicles(name=name, plane=plane, num=num) self._createJoints(name=name, follicles=follicles, rad=rad) pm.delete(crv1, crv2) pymelLogger.info('Ended: %s' % _name) pymelLogger.info('Build successful!')
def exportAsset(self, fileName=None, assetPath=None, unityPath=None, ignore=None): """ Export 'custom' group geo and SH skeleton. """ pymelLogger.debug('Starting: exportAsset()...') # Export to directories with type and asset file name print unityPath print assetPath found = False for typ in self.assetTypes: platform = sys.platform if 'win' in platform: #pathElems = assetPath.split(os.sep) pathElems = assetPath.split('/') else: if '/' in assetPath: pathElems = assetPath.split('/') else: pathElems = assetPath.split('\\') if typ in pathElems: pymelLogger.debug('exportAsset(): Type: %s'%typ) unityPath = unityPath + '/%s/'%typ + os.path.basename(assetPath[:-4]) found = True break if not found: msg = 'exportAsset(): Asset is not in a directory named after a type.' pymelLogger.error(msg) raise Exception(msg) pymelLogger.debug('File name: %s'%fileName) pymelLogger.debug('Asset path: %s'%assetPath) pymelLogger.debug('Unity path: %s'%unityPath) # Make AssetLib fbx / Unity directories if they do not exist try: if not os.path.isdir( assetPath ): os.makedirs( assetPath ) if not os.path.isdir( unityPath ): os.makedirs( unityPath ) except Exception,e: pymelLogger.error('exportAsset(): Error creating directory.') pymelLogger.error(e) raise Exception(e)
def _fbxExport(self, selection=None, fileName=None, prefix=None, assetPath=None, unityPath=None, rig=False, asset=False, anim=False, camera=False): ''' Selection: Names of objects to export prefix: [email protected] assetPath: Directory to export fbx in AssetLib unityPath: Directory to export fbx for unity rig/asset/anim/camera: Determine FBX options ''' pymelLogger.debug('Starting: fbxExport()...' ) pymelLogger.debug('Exporting: %s'%selection) pymelLogger.debug('Prefix: %s'%prefix) pymelLogger.debug('Asset path: %s'%assetPath) pymelLogger.debug('Unity path: %s'%unityPath) try: pm.parent(selection,w=True) except: pm.select(selection,r=1) # Determine export file name if prefix: fileN = os.path.basename(fileName)[:-3] fileN = prefix+'@'+fileN+'.fbx' else: fileN = os.path.basename(fileName)[:-3] fileN = fileN + '.fbx' pymelLogger.debug('fileN: %s'%fileN) # Place file in fbx folder in proper location # anim/typ=1 and rig have a different folder structure unityFile = unityPath + '/' + fileN assetFile = assetPath + '/' + fileN pymelLogger.debug('unityFile: %s'%unityFile) pymelLogger.debug('assetFile: %s'%assetFile) startFrame = int( cmds.playbackOptions(q=1, min=1) ) endFrame = int( cmds.playbackOptions(q=1, max=1) ) # FBX OPTIONS! # Geometry mel.eval("FBXExportSmoothingGroups -v true") mel.eval("FBXExportHardEdges -v false") mel.eval("FBXExportTangents -v false") mel.eval("FBXExportSmoothMesh -v true") mel.eval("FBXExportInstances -v false") mel.eval("FBXExportReferencedContainersContent -v false") # Animation if anim: mel.eval("FBXExportApplyConstantKeyReducer -v true") mel.eval("FBXExportBakeResampleAnimation -v true") mel.eval("FBXExportBakeComplexAnimation -v true") mel.eval("FBXExportBakeComplexStart -v "+str(startFrame)) mel.eval("FBXExportBakeComplexEnd -v "+str(endFrame)) mel.eval("FBXExportBakeComplexStep -v 1") mel.eval("FBXExportUseSceneName -v false") mel.eval("FBXExportQuaternion -v euler") if asset: mel.eval("FBXExportShapes -v true") mel.eval("FBXExportSkins -v true") if camera: mel.eval("FBXExportCameras -v true") else: mel.eval("FBXExportCameras -v false") # Constraints mel.eval("FBXExportConstraints -v false") # Lights mel.eval("FBXExportLights -v false") # Embed Media mel.eval("FBXExportEmbeddedTextures -v false") # Connections mel.eval("FBXExportInputConnections -v false") # Axis Conversion mel.eval("FBXExportUpAxis y") # version mel.eval("FBXExportFileVersion FBX201100") # Type mel.eval("FBXExportInAscii -v true") # Export! exported = [] mel.eval('FBXExport -f "'+ assetFile +'" -exportFormat "fbx" -s;') exported.append(assetFile) pymelLogger.debug('fbxExport(): Exported: %s'%assetFile ) # Copy fbx and textures folder to unitypath # /fbx try: # Copy .fbx files to unity dir onlyfiles = [ os.path.join(assetPath+"/"+f) for f in os.listdir(assetPath) if os.path.isfile( assetPath+"/"+f) ] fbxs = [ f for f in onlyfiles if f.endswith('.fbx') ] for f in fbxs: fName = os.path.basename(f) dst = unityPath+'/fbx/'+fName dstDir = os.path.join(unityPath,'fbx') if not os.path.exists(dstDir): print 'created!' os.makedirs(dstDir) try: shutil.copy(f, dst) except: shutil.rmtree(dst) shutil.copy(f, dst) pymelLogger.debug('fbxExport(): Copied from:%s'%f) pymelLogger.debug('fbxExport(): Copied to:%s'%dst) except Exception,e: pymelLogger.error('fbxExport(): %s'%e )
ns = ns[0] elif len(ns) > 2: ns = ns[-2] pm.select(root, r=1) self._importRefDeleteNS() self._bakeAnim( root ) if ns: result = self._fbxExport( selection=root, fileName=fileName, prefix=ns, assetPath=assetPath, unityPath=unityPath, anim=True ) else: msg = 'Rig has no namespace. Make sure it is referenced. Nothing exported.' pymelLogger.error(msg) raise Exception(msg) if result: results.append(result) exportedRig = True pm.delete(root) else: pymelLogger.error('FBX did not export for "%s:%s"'%(ns,root)) if not exportedRig: msg = 'No Rigs in the scene to be exported!' cmds.warning( msg ) pymelLogger.warning( msg ) # Export camera(s)
def _fbxExport(self, selection=None, fileName=None, prefix=None, assetPath=None, unityPath=None, rig=False, asset=False, anim=False, camera=False): ''' Selection: Names of objects to export prefix: [email protected] assetPath: Directory to export fbx in AssetLib unityPath: Directory to export fbx for unity rig/asset/anim/camera: Determine FBX options ''' pymelLogger.debug('Starting: fbxExport()...') pymelLogger.debug('Exporting: %s' % selection) pymelLogger.debug('Prefix: %s' % prefix) pymelLogger.debug('Asset path: %s' % assetPath) pymelLogger.debug('Unity path: %s' % unityPath) try: pm.parent(selection, w=True) except: pm.select(selection, r=1) # Determine export file name if prefix: fileN = os.path.basename(fileName)[:-3] fileN = prefix + '@' + fileN + '.fbx' else: fileN = os.path.basename(fileName)[:-3] fileN = fileN + '.fbx' pymelLogger.debug('fileN: %s' % fileN) # Place file in fbx folder in proper location # anim/typ=1 and rig have a different folder structure unityFile = unityPath + '/' + fileN assetFile = assetPath + '/' + fileN pymelLogger.debug('unityFile: %s' % unityFile) pymelLogger.debug('assetFile: %s' % assetFile) startFrame = int(cmds.playbackOptions(q=1, min=1)) endFrame = int(cmds.playbackOptions(q=1, max=1)) # FBX OPTIONS! # Geometry mel.eval("FBXExportSmoothingGroups -v true") mel.eval("FBXExportHardEdges -v false") mel.eval("FBXExportTangents -v false") mel.eval("FBXExportSmoothMesh -v true") mel.eval("FBXExportInstances -v false") mel.eval("FBXExportReferencedContainersContent -v false") # Animation if anim: mel.eval("FBXExportApplyConstantKeyReducer -v true") mel.eval("FBXExportBakeResampleAnimation -v true") mel.eval("FBXExportBakeComplexAnimation -v true") mel.eval("FBXExportBakeComplexStart -v " + str(startFrame)) mel.eval("FBXExportBakeComplexEnd -v " + str(endFrame)) mel.eval("FBXExportBakeComplexStep -v 1") mel.eval("FBXExportUseSceneName -v false") mel.eval("FBXExportQuaternion -v euler") if asset: mel.eval("FBXExportShapes -v true") mel.eval("FBXExportSkins -v true") if camera: mel.eval("FBXExportCameras -v true") else: mel.eval("FBXExportCameras -v false") # Constraints mel.eval("FBXExportConstraints -v false") # Lights mel.eval("FBXExportLights -v false") # Embed Media mel.eval("FBXExportEmbeddedTextures -v false") # Connections mel.eval("FBXExportInputConnections -v false") # Axis Conversion mel.eval("FBXExportUpAxis y") # version mel.eval("FBXExportFileVersion FBX201100") # Type mel.eval("FBXExportInAscii -v true") # Export! exported = [] mel.eval('FBXExport -f "' + assetFile + '" -exportFormat "fbx" -s;') exported.append(assetFile) pymelLogger.debug('fbxExport(): Exported: %s' % assetFile) # Copy fbx and textures folder to unitypath # /fbx try: # Copy .fbx files to unity dir onlyfiles = [ os.path.join(assetPath + "/" + f) for f in os.listdir(assetPath) if os.path.isfile(assetPath + "/" + f) ] fbxs = [f for f in onlyfiles if f.endswith('.fbx')] for f in fbxs: fName = os.path.basename(f) dst = unityPath + '/fbx/' + fName dstDir = os.path.join(unityPath, 'fbx') if not os.path.exists(dstDir): print 'created!' os.makedirs(dstDir) try: shutil.copy(f, dst) except: shutil.rmtree(dst) shutil.copy(f, dst) pymelLogger.debug('fbxExport(): Copied from:%s' % f) pymelLogger.debug('fbxExport(): Copied to:%s' % dst) except Exception, e: pymelLogger.error('fbxExport(): %s' % e)
ns = ns[0] elif len(ns) > 2: ns = ns[-2] pm.select(root, r=1) self._importRefDeleteNS() self._bakeAnim(root) if ns: result = self._fbxExport(selection=root, fileName=fileName, prefix=ns, assetPath=assetPath, unityPath=unityPath, anim=True) else: msg = 'Rig has no namespace. Make sure it is referenced. Nothing exported.' pymelLogger.error(msg) raise Exception(msg) if result: results.append(result) exportedRig = True pm.delete(root) else: pymelLogger.error('FBX did not export for "%s:%s"' % (ns, root)) if not exportedRig: msg = 'No Rigs in the scene to be exported!' cmds.warning(msg) pymelLogger.warning(msg)