Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.cmds as cmds
- import os
- import maya.mel as mel
- Width_Height_Open = [ 250 , 50 ]
- Red_Btn_Col = ( .73 , .29 , .29 )
- Bright_Red_Btn_Col = ( 1 , .2 , .2 )
- Yel_Btn_Col = ( .84 , .76 , .31 )
- Art_Btn_Col = ( .50 , .80 , .50 )
- Anims_Btn_Col = ( .50 , .60 , .70 )
- Misc_Btn_Col = ( .80 , .50 , .50 )
- Grn_Btn_Col = ( .34 , .76 , .31 )
- Drk_Grey = [ .3 , .3 , .3 ]
- Lte_Grey = [ .47 , .45 , .45 ]
- global MainJntToFind
- MainJntToFind = str( 'bjRoot')
- """ Change Log:
- # 2/4/2014: Updated exporter to remove scale nodes from the scene before exporting rig ( stops squished rigs.. )
- """
- global CurrentPath_full
- CurrentPath_full = ''
- BodyPartListToRemove = [ 'default' , 'm_npc_' , 'm_char_' ]
- Bits_To_Del = [ '*tmXML*' , '*Guide*' , '*Snap*' , '*deleteme*'] # items deleted from the scene before export to make sure the fbx is clean.
- def init():
- FBXExport_Win()
- def FBXExport_Win_TmpMode_On():
- cmds.rowColumnLayout( 'FBXExport_MainWin' , edit=True , bgc= ( .1 , .1 , .1 ) )
- cmds.rowColumnLayout( 'FBXExport_Btns' , edit = True , vis=False )
- cmds.rowColumnLayout( 'FBXExport_List_title' , edit = True , vis=False )
- cmds.scrollLayout( 'FBXExport_List_scroll' , edit = True , vis=False )
- cmds.frameLayout( 'FBXExport_Prop_OptsTab' , edit = True , vis=False )
- cmds.rowColumnLayout( 'FBXExport_Btns_Export_Col' , edit = True , vis=False )
- cmds.button( 'btn_TmpMode_1' , bgc = Bright_Red_Btn_Col , label='You are in a temporary file...' , parent = 'FBXExport_MainWin' , command = 'FBXExport_Win_TmpMode_OpenFile()' )
- cmds.button( 'btn_TmpMode_2' , bgc = Bright_Red_Btn_Col , label='..click here to reload the actual file?' , parent = 'FBXExport_MainWin' , command = 'FBXExport_Win_TmpMode_OpenFile()' )
- def FBXExport_Win_TmpMode_Off():
- cmds.rowColumnLayout( 'FBXExport_MainWin' , edit=True , bgc= Drk_Grey )
- cmds.rowColumnLayout( 'FBXExport_Btns' , edit = True , vis=True )
- cmds.rowColumnLayout( 'FBXExport_List_title' , edit = True , vis=True )
- cmds.scrollLayout( 'FBXExport_List_scroll' , edit = True , vis=True )
- cmds.frameLayout( 'FBXExport_Prop_OptsTab' , edit = True , vis=True )
- cmds.rowColumnLayout( 'FBXExport_Btns_Export_Col' , edit = True , vis=True )
- buttons_todel1 = cmds.button( 'btn_TmpMode_1' , exists=True )
- if buttons_todel1 is True:
- cmds.deleteUI( 'btn_TmpMode_1' )
- cmds.deleteUI( 'btn_TmpMode_2' )
- else:
- pass
- def FBXExport_Win_TmpMode_OpenFile():
- global Current_File
- cmds.file( Current_File , o=True , f=True)
- FBXExport_Win_TmpMode_Off()
- def FBXExport_Win_ExportPathUpdate(): #edits the path button
- global CurrentPath_full
- CurrentPath = cmds.button( 'FBXExport_Prop_PathBtn' , query = True , label = True )
- if CurrentPath is 'Export Meshs to :- (directory path )' :
- CurrentPath = ''
- CurrentPath_full = ''
- else:
- pass
- tmp = cmds.fileDialog2( dir = CurrentPath , dialogStyle = 1 , fm = 3 )
- if tmp is None:
- pass
- else:
- cmds.button( 'FBXExport_Prop_PathBtn' , edit = True , label = tmp[0] , width = Width_Height_Open[0] , ann = tmp[0] )
- CurrentPath_full = tmp[0]
- def FBXExport_Win_ListUpdate_ADD():
- Current_Sel = Items_Selected_BW()
- if len(Current_Sel) < 1:
- pass
- else:
- tmp = cmds.text( 'FBXExport_ItemsTxtAll' , query = True , label = True )
- cmds.select( clear=True )
- if tmp is None:
- pass
- else:
- if len(tmp) < 1:
- pass
- else:
- Current_In_List = tmp.split('@')
- for x in Current_In_List:
- if x is '':
- pass
- else:
- cmds.select( x , add=True )
- cmds.select( Current_Sel , add=True )
- Items_List = cmds.ls( selection=True )
- Items_List_String = '@'.join( Items_List )
- cmds.text( 'FBXExport_ItemsTxtAll' , edit = True , label = Items_List_String )
- FBXExport_Win_ListUpdate_Updater( Items_List )
- def FBXExport_Win_ListUpdate_REM():
- Current_Sel = Items_Selected_BW()
- if len(Current_Sel) < 1:
- pass
- else:
- tmp = cmds.text( 'FBXExport_ItemsTxtAll' , query = True , label = True )
- cmds.select( clear=True )
- if tmp is None:
- pass
- else:
- Current_In_List = tmp.split('@')
- if len(Current_In_List) < 2:
- pass
- else:
- cmds.select( clear=True )
- cmds.select( Current_In_List , add=True )
- cmds.select( Current_Sel , deselect=True )
- Items_List = cmds.ls( selection=True )
- Items_List_String = '@'.join( Items_List )
- cmds.text( 'FBXExport_ItemsTxtAll' , edit = True , label = Items_List_String )
- FBXExport_Win_ListUpdate_Updater( Items_List )
- def FBXExport_Win_ListUpdate_CLR():
- cmds.text( 'FBXExport_ItemsTxtAll' , edit = True , label = '' )
- OldBtns = cmds.rowColumnLayout( 'FBXExport_List' , query =True , ca=True )
- if OldBtns is None:
- pass
- else:
- for x in OldBtns:
- cmds.deleteUI(x)
- cmds.scrollLayout( 'FBXExport_List_scroll' , edit=True , h= 10 , vis=False )
- global Glbl_MeshList
- Glbl_MeshList = []
- def FBXExport_Win_ListUpdate_Updater( list ):
- MaxHeight = 250
- OldBtns = cmds.rowColumnLayout( 'FBXExport_List' , query =True , ca=True )
- if OldBtns is None:
- pass
- else:
- for x in OldBtns:
- cmds.deleteUI(x)
- Char_Lengths = []
- for x in list:
- Char_Lengths.append( (len(x)) )
- print OldBtns
- if len(Char_Lengths) < 1:
- Val = 10
- adder = 1
- else:
- Char_Lengths.sort( reverse=True )
- Val = (sum(Char_Lengths) / len(Char_Lengths))
- adder = 1
- cmds.deleteUI( 'FBXExport_List' )
- if Val < 20:
- if Val < 15:
- if Val < 10:
- cmds.rowColumnLayout( 'FBXExport_List' , numberOfColumns=4 , width = Width_Height_Open[0] , parent = 'FBXExport_List_scroll' )
- adder = 4
- else:
- cmds.rowColumnLayout( 'FBXExport_List' , numberOfColumns=3 , width = Width_Height_Open[0] , parent = 'FBXExport_List_scroll' )
- adder = 3
- else:
- cmds.rowColumnLayout( 'FBXExport_List' , numberOfColumns=2 , width = Width_Height_Open[0] , parent = 'FBXExport_List_scroll' )
- adder = 2
- else:
- cmds.rowColumnLayout( 'FBXExport_List' , numberOfColumns=1 , width = Width_Height_Open[0] , parent = 'FBXExport_List_scroll' )
- count = 0
- while count < len(list):
- count+=adder
- Num_Rows = ( count / adder )
- Scroll_Height = ( (Num_Rows * 20) + 20 )
- if Scroll_Height < MaxHeight :
- cmds.scrollLayout( 'FBXExport_List_scroll' , edit=True , h= Scroll_Height , vis=True )
- else:
- cmds.scrollLayout( 'FBXExport_List_scroll' , edit=True , h= MaxHeight , vis=True )
- count = .3
- for x in list:
- print x
- print ( "BtnItem_SelectForMe(" + x + ")" )
- cmds.button( x , bgc = [ 0.5 , count , 0.3 ], label = x , parent = 'FBXExport_List' , command = 'BtnItem_SelectForMe("' + x + '")' )
- if count < .6:
- count+=.1
- else:
- count = .3
- global Glbl_MeshList
- Glbl_MeshList = list
- # FBXExport_Win_TagAtr( 'Read' )
- def BtnItem_SelectForMe( Item ):
- print 'fired'
- print
- cmds.select( clear = True )
- cmds.select( Item )
- def Items_Selected_BW(): #returns selected + error msgs
- selcted= []
- selcted = cmds.ls( selection=True , transforms = True )
- if selcted is None:
- pass
- else:
- return selcted
- def Find_User_PathForTmp():
- User_Path = ''
- pass #for now just going to give direct path above
- Script_Dir_Test = cmds.internalVar( uwd =True)
- if 'Library/Preferences/' in Script_Dir_Test:
- pass #Mac address!
- tmp = Script_Dir_Test.split( 'Library' )
- User_Path = Script_Dir_Test
- else:
- pass #must be pc address...
- tmp = Script_Dir_Test.split( 'maya' )
- User_Path = Script_Dir_Test
- print ( "Saving temp Location :- \n" + User_Path + "\n" ) # doesnt seem to be firing
- return User_Path
- def CleanUpProc():
- global Current_File
- Current_File = FileImporter() #imports all refs in scene and saves to tmp location, returns this address
- FBX_UnitsSettings()
- def FBX_UnitsSettings():
- pass #sort maya units 1st!
- cmds.currentUnit( linear='cm' , t='ntsc' ) #sets units as meter and time as 30fps ntsc
- # cmds.currentUnit( linear='cm' , t='game' ) #sets units as meter and time as 30fps ntsc
- # cmds.currentUnit( linear='cm' , t='ntsc' ) #sets units as meter and time as 30fps ntsc
- # cmds.currentUnit( linear='m' , t='ntsc' ) #sets units as meter and time as 30fps ntsc
- pass #set settings
- mel.eval('FBXResetExport')
- mel.eval('FBXExportFileVersion "FBX200900"')
- mel.eval('FBXExportInputConnections -v 1')
- mel.eval('FBXExportUseSceneName -v true')
- mel.eval('FBXExportAnimationOnly -v false')
- mel.eval('FBXExportSmoothingGroups -v true')
- mel.eval('FBXExportSmoothMesh -v true')
- mel.eval('FBXExportSkins -v true')
- mel.eval('FBXExportEmbeddedTextures -v false')
- mel.eval('FBXExportScaleFactor 1.0')
- # mel.eval('FBXExportGenerateLog -v false')
- def Export_Opt_Prop():
- ExportAll_Val = cmds.checkBox( 'FBXExport_Check_ExportAll' , edit=True , value=False ) # export entire scene, use scene name
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , edit=True , value=False ) # export bodyparts
- AnimNOMesh_Val = cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , edit=True , value=False ) #export meshes AND animations
- IsAnimated_Val = cmds.checkBox( 'FBXExport_Check_ISAnimated' , edit=True , value=False )
- # FBXExport_Win_TagAtr( 'Export' )
- MeshTrigger()
- def Export_Opt_PropAnim():
- ExportAll_Val = cmds.checkBox( 'FBXExport_Check_ExportAll' , edit=True , value=False ) # export entire scene, use scene name
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , edit=True , value=False ) # export bodyparts
- AnimNOMesh_Val = cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , edit=True , value=True ) #export meshes AND animations
- IsAnimated_Val = cmds.checkBox( 'FBXExport_Check_ISAnimated' , edit=True , value=True )
- # FBXExport_Win_TagAtr( 'Export' )
- MeshTrigger()
- def Export_Opt_Char():
- global Glbl_MeshList
- #check weights are fine first!
- test = getSkinWeights()
- print ( 'test = ' + str(test) )
- if test is 0:
- ExportAll_Val = cmds.checkBox( 'FBXExport_Check_ExportAll' , edit=True , value=True ) # export entire scene, use scene name
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , edit=True , value=True ) # export bodyparts
- AnimNOMesh_Val = cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , edit=True , value=True ) #export meshes AND animations
- IsAnimated_Val = cmds.checkBox( 'FBXExport_Check_ISAnimated' , edit=True , value=False )
- AnimTrigger()
- else:
- cmds.warning( 'see warning! stopping export.' )
- def Export_Opt_CharAnimNoMesh():
- ExportAll_Val = cmds.checkBox( 'FBXExport_Check_ExportAll' , edit=True , value=False ) # export entire scene, use scene name
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , edit=True , value=False ) # export bodyparts
- AnimNOMesh_Val = cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , edit=True , value=False ) #export meshes AND animations
- IsAnimated_Val = cmds.checkBox( 'FBXExport_Check_ISAnimated' , edit=True , value=False )
- # FBXExport_Win_TagAtr( 'Export' )
- AnimTrigger()
- def Export_Opt_CharAnimAndMesh():
- global Glbl_MeshList
- #check weights are fine first!
- test = getSkinWeights()
- print ( 'test = ' + str(test) )
- if test is 0:
- ExportAll_Val = cmds.checkBox( 'FBXExport_Check_ExportAll' , edit=True , value=False ) # export entire scene, use scene name
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , edit=True , value=False ) # export bodyparts
- AnimNOMesh_Val = cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , edit=True , value=True ) #export meshes AND animations
- IsAnimated_Val = cmds.checkBox( 'FBXExport_Check_ISAnimated' , edit=True , value=False )
- # FBXExport_Win_TagAtr( 'Export' )
- AnimTrigger()
- else:
- cmds.warning( 'see warning! stopping export..' )
- def Export_Opt_CharBodyParts():
- global Glbl_MeshList
- test = getSkinWeights()
- print ( 'test = ' + str(test) )
- if test is 0:
- # FBXExport_Win_TagAtr( 'Export' )
- for x in Glbl_MeshList:
- cmds.select( x )
- ExportAll_Val = cmds.checkBox( 'FBXExport_Check_ExportAll' , edit=True , value=False ) # export entire scene, use scene name
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , edit=True , value=True ) # export bodyparts
- AnimNOMesh_Val = cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , edit=True , value=False ) #export meshes AND animations
- IsAnimated_Val = cmds.checkBox( 'FBXExport_Check_ISAnimated' , edit=True , value=False )
- MeshTrigger()
- else:
- cmds.warning( 'see warning! stopping export...' )
- def FBXExport_Win_CenteredItems():
- global Glbl_MeshList
- CenterCheck_Val = cmds.checkBox( 'FBXExport_Check_Center' , query=True , value=True )
- if CenterCheck_Val is True:
- cmds.select( clear =True )
- Newgroup = cmds.group( em=True, name= 'CenterGrp_Wrld' )
- for x in Glbl_MeshList:
- cmds.select( clear =True )
- NewCons = cmds.parentConstraint( Newgroup , x , mo=False)
- cmds.select( clear =True )
- cmds.select( NewCons )
- cmds.Delete()
- cmds.select( Newgroup )
- cmds.Delete()
- cmds.select( clear=True )
- else:
- pass
- def FBXExport_Win_IsAnimated():
- IsAnimated_Val = cmds.checkBox( 'FBXExport_Check_ISAnimated' , query=True , value=True )
- if IsAnimated_Val is True:
- FBX_UnitsSettings()
- mel.eval('FBXProperty Export|IncludeGrp|Animation -v true;')
- Time_Start = cmds.playbackOptions(query=True , minTime=True)
- Time_End = cmds.playbackOptions(query=True , maxTime=True)
- mel.eval('FBXExportBakeComplexAnimation -v true;')
- mel.eval('FBXExportBakeComplexStart -v ' + str(Time_Start) + ';')
- mel.eval('FBXExportBakeComplexEnd -v ' + str(Time_End) + ';')
- else:
- FBX_UnitsSettings()
- mel.eval('FBXExportInputConnections -v 0;')
- mel.eval('FBXExportAnimationOnly -v false;')
- mel.eval('FBXProperty Export|IncludeGrp|Animation -v false;')
- mel.eval('FBXExportSkins -v false')
- def FBXExport_Win_ExportAll():
- global Current_File
- global Glbl_MeshList
- global CurrentPath_full
- ExportAll_Val = cmds.checkBox( 'FBXExport_Check_ExportAll' , query=True , value=True )
- if ExportAll_Val is True:
- print 'exporting using scene name instead of mesh/parts'
- FileName = FileNameStrip()
- tmp = ( CurrentPath_full + '\\' + FileName + '.Fbx' )
- FinalPath_Mixed = tmp.replace('\\' , '/')
- start = 'FBXExport -f '
- end = ' -s' #only export selected part/toggle
- print ( start + '"' + FinalPath_Mixed + '"' + ';')
- cmds.select( Glbl_MeshList )
- import maya.mel as mel
- mel.eval( start + '"' + FinalPath_Mixed + '"' + end + ';')
- # mel.eval( start + '"' + FinalPath_Mixed + '"' + ';')
- else:
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , query=True , value=True )
- if BodyParts_Val is True:
- print 'doing body parts'
- FBXExport_Win_ExportBodyParts()
- else:
- print 'exporting each mesh/parts'
- for x in Glbl_MeshList:
- tmp33 = NameStrip( x )
- PropName_Val = cmds.checkBox( 'FBXExport_Check_DontAddProp_Name' , query=True , value=True )
- if PropName_Val is True:
- ItemName = tmp33
- else:
- tmp44 = tmp33.replace( 'prop_' , '' )
- ItemName = tmp44.replace( 'm_' , 'prop_' )
- tmp = ( CurrentPath_full + '\\' + ItemName + '.Fbx' )
- FinalPath_Mixed = tmp.replace('\\' , '/')
- start = 'FBXExport -f '
- end = ' -s' #only export selected part/toggle
- print ( start + '"' + FinalPath_Mixed + '"' + ';')
- cmds.select( x )
- import maya.mel as mel
- mel.eval( start + '"' + FinalPath_Mixed + '"' + end + ';')
- def FBXExport_Win_ReLoadFile():
- global Current_File
- Reload_Val = cmds.checkBox( 'FBXExport_Check_ReOpen' , query=True , value=True )
- if Reload_Val is False:
- cmds.file( Current_File , o=True , f=True)
- FBXExport_Win_TmpMode_Off()
- else:
- FBXExport_Win_TmpMode_On()
- def getSkinWeights():
- ''' Get the weights per vertex on the meshName with the skinClusterName'''
- MaxValue_Infs = cmds.intSliderGrp( 'FBXExport_MaxInfluences' , query=True , v=True )
- global Glbl_MeshList
- #check weights are fine first!
- Test_Verts = []
- for x in Glbl_MeshList:
- mesh = x
- cmds.select( clear=True )
- cmds.select( x )
- mel.eval ('$mesh = "%s";' % (mesh))
- skinClusterName = mel.eval('findRelatedSkinCluster($mesh);')
- if len(skinClusterName) < 1:
- print 'no skin cluster found, passing'# return 0
- else:
- weights = []
- cmds.skinPercent( skinClusterName , mesh , pruneWeights=0.015 )
- # get the Influence Objects
- influenceObjects = cmds.skinCluster(skinClusterName, q=True, weightedInfluence=True)
- # get the size of the vertex weight list
- weightListSize = cmds.getAttr(skinClusterName + ".weightList", size=True)
- # build weight dictionary
- for vertexId in range(0,weightListSize):
- # to store vertex weights
- vertexWeights = {}
- for influenceId in range(len(influenceObjects)):
- weight = cmds.getAttr(skinClusterName + ".weightList[%d].weights[%d]" % (vertexId,influenceId))
- #print weight
- # only store non-zero weights
- if weight != 0:
- vertexWeights[influenceId] = weight
- # store the weights for the vertex id
- if len(vertexWeights) > MaxValue_Infs :
- BadVert = ( str(mesh) + '.vtx[' + str(vertexId) + ']' )
- weights.append( BadVert )
- else:
- pass
- if len(weights) < 1:
- print ( 'all weight influences are fine on ' + x + '\n')
- else:
- cmds.warning ( 'there are ' + str(len(weights)) + ' vertexs with weights beyond what you have selected in the exporter on .. ' + x )
- for y in weights:
- Test_Verts.append(y)
- if len(Test_Verts) > 1:
- print len(Test_Verts)
- cmds.select( Test_Verts )
- return Test_Verts
- else:
- return 0
- def FileNameStrip():
- global Current_File
- tmp = Current_File.split('/')
- tmp2 = tmp[-1]
- tmp3 = tmp2.split('.')
- tmp4 = tmp3[0]
- return tmp4.lower()
- def NameStrip( Item ):
- tmp = Item.split(':')
- tmp2 = tmp[-1]
- tmp3 = tmp2.replace( '|' , '' )
- return tmp3.lower()
- def BodyPartClean( Item ):
- Item = NameStrip( Item )
- for x in BodyPartListToRemove:
- Item = Item.replace( x , '' )
- return Item.lower()
- def BodyPartClean_Numerix( Item ):
- import re
- Item_cleaned = re.sub('[^a-z_]','',Item)
- return Item_cleaned
- def FileCheck_Exists( file_ToLoad ) :
- Exists_test = cmds.file( file_ToLoad , q=True, ex=True )
- if Exists_test is True:
- return True
- else:
- os.makedirs( file_ToLoad )
- return False
- def MeshTrigger():
- global CurrentPath_full
- if CurrentPath_full is '':
- print 'path not found'
- FBXExport_Win_ExportPathUpdate()
- else:
- print 'path found moving on.'
- global Current_File
- global Glbl_MeshList
- ## here needs a pause to check user saved file?!
- _userChose = cmds.confirmDialog( title='Have you saved?!', message=( 'Are you sure you have saved, unsaved changes will be lost ' + os.environ['USER'] + '?'), button=['Yes','No'], defaultButton='Yes', cancelButton='No', dismissString='No' )
- if _userChose == 'Yes':
- FBXExport_Win_TagAtr( 'Export' )
- FBXExport_Win_TmpMode_On()
- CleanUpProc()
- FBXExport_Win_CenteredItems()
- FBXExport_Win_IsAnimated()
- FBXExport_Win_ExportAll()
- FBXExport_Win_ReLoadFile()
- def AnimExport_NoMesh():
- AnimNOMesh_Val = cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , query=True , value=True )
- if AnimNOMesh_Val is True:
- BodyParts_Val = cmds.checkBox( 'FBXExport_Check_BodyParts' , query=True , value=True )
- if BodyParts_Val is True:
- mel.eval('FBXProperty Export|IncludeGrp|Animation -v false;')
- print 'keeping anims and meshes' #used for exporting incidental creature anims
- else:
- mel.eval('FBXProperty Export|IncludeGrp|Animation -v true;') #used for exporting character setup meshes with no anims.
- global Glbl_MeshList
- print Glbl_MeshList
- if len(Glbl_MeshList) < 1:
- pass
- else:
- for x in Glbl_MeshList:
- print x
- try:
- cmds.parent( x , world=True )
- except:
- print ( 'error selecting ' + x )
- tmp = cmds.ls( ( '*' + MainJntToFind ) , r=True , type='joint' )
- if len(tmp) > 0:
- cmds.select(clear=True)
- cmds.select( ado=True )
- cmds.select( tmp[0] , deselect=True)
- for x in Glbl_MeshList:
- try:
- cmds.select( x , deselect=True)
- except:
- print ( 'error selecting for scene clean up ' + x )
- cmds.delete()
- else:
- tmp = cmds.ls( ( '*' + MainJntToFind ) , r=True , type='joint' )
- if len(tmp) > 0:
- cmds.select(clear=True)
- cmds.select(ado=True)
- cmds.select( tmp[0] , deselect=True)
- cmds.delete()
- print 'removing meshes from scene before export!'
- CleanUpper()
- def AnimTrigger():
- global CurrentPath_full
- if CurrentPath_full is '':
- print 'path not found'
- FBXExport_Win_ExportPathUpdate()
- else:
- print 'path found moving on.'
- global Current_File
- global Glbl_MeshList
- FBXExport_Win_TagAtr( 'Export' )
- ## here needs a pause to check user saved file?!
- _userChose = cmds.confirmDialog( title='Have you saved?!', message=( 'Are you sure you have saved, unsaved changes will be lost ' + os.environ['USER'] + '?'), button=['Yes','No'], defaultButton='Yes', cancelButton='No', dismissString='No' )
- if _userChose == 'Yes':
- FBXExport_Win_TagAtr( 'Export' )
- FBXExport_Win_TmpMode_On()
- CleanUpProc() #imports all ref files and sets maya units
- Export_Baker_Cmd() #bake down rig model
- CleanUpper()
- FileName = FileNameStrip()
- FileClean = BodyPartClean( FileName )
- AnimExport_NoMesh()
- tmp = ( CurrentPath_full + '\\' + FileName + '.Fbx' )
- FinalPath_Mixed = tmp.replace('\\' , '/')
- start = 'FBXExport -f '
- print ( start + '"' + FinalPath_Mixed + '"' + ';')
- mel.eval( start + '"' + FinalPath_Mixed + '"' + ';')
- FBXExport_Win_ReLoadFile()
- def CleanUpper():
- for x in Bits_To_Del:
- tmp = cmds.ls( x , r=True )
- if tmp is None:
- pass
- else:
- if len(tmp) < 1:
- pass
- else:
- cmds.select( clear=True )
- cmds.select( tmp )
- cmds.delete()
- def FBXExport_Win_TagAtr( type ):
- global CurrentPath_full
- def FileCheck_Exists_Importer( file_ToLoad ):
- Exists_test = cmds.file( file_ToLoad , q=True, ex=True )
- if Exists_test is True:
- return True
- else:
- print file_ToLoad
- return False
- def FileImporter(): #looks for any refferance files and imports all..
- global Current_File
- Current_File = ''
- Save_File = ''
- global File_Tmp_Location_Export
- tmp = cmds.file( sn=True , query=True)
- tmp2 = tmp.split('/')
- File_Tmp_Location_Export = tmp2[-1]
- File_Tmp_Location_Save = 'TmpSave.ma' #this is the filename, can be changed
- Current_File = cmds.file( sn=True , query=True)
- pass #auto save!
- if len(Current_File) < 2: #file not saved, create tmp save!!!
- print Current_File
- else:
- print Current_File
- pass# Now to break the file
- File_list = ['']
- File_list = cmds.file( list=True , query=True)
- if len( File_list ) > 1:
- for x in File_list[1:]:
- Test_MA = '.ma' in x
- if Test_MA is True:
- print 'importing:'
- print x
- print '\n'
- cmds.file( x , ir=True , f=True )
- else:
- pass
- else:
- pass
- return Current_File
- def Find_User_PathForTmp():
- User_Path = ''
- pass #for now just going to give direct path above
- Script_Dir_Test = cmds.internalVar( uwd =True)
- if 'Library/Preferences/' in Script_Dir_Test:
- pass #Mac address!
- tmp = Script_Dir_Test.split( 'Library' )
- User_Path = Script_Dir_Test
- else:
- pass #must be pc address...
- tmp = Script_Dir_Test.split( 'maya' )
- User_Path = Script_Dir_Test
- return User_Path
- def RenameBits():
- HI_Top_Jnt= cmds.ls( ( '*' + MainJntToFind ) , type='joint' )
- if len(HI_Top_Jnt) < 1:
- HI_Top_Jnt= cmds.ls( ( '*:' + MainJntToFind ) , type='joint' )
- if len(HI_Top_Jnt) < 1:
- print 'hip joint not found, please rename to Hip_Jnt and try again'
- else:
- Search_Char_Rig = cmds.ls( '*:Character_Rig')
- if len(Search_Char_Rig) < 1:
- print 'character rig not found, attempting basic export?'
- print ( 'Hip Jnt Found = ' + str(HI_Top_Jnt) )
- cmds.select( HI_Top_Jnt)
- cmds.pickWalk( d='up' )
- cmds.select( hi=True )
- tmp = cmds.ls( selection=True , fl=True , transforms=True )
- count = 1
- print tmp
- while count < len(tmp):
- count_r = (len(tmp) - count)
- x = tmp[count_r]
- print x
- tmp1 = x.split(':')
- tmp2 = tmp1[-1]
- cmds.select(clear=True)
- cmds.select( x )
- cmds.rename( tmp2 )
- print tmp2
- count+=1
- cmds.select(clear=True)
- cmds.select( tmp[0] )
- tmp1 = tmp[0].split(':')
- tmp2 = tmp1[-1]
- cmds.rename( tmp2 )
- else:
- cmds.select( clear=True )
- cmds.select( Search_Char_Rig )
- cmds.pickWalk( d='up' )
- cmds.select( hi=True )
- tmp = cmds.ls( selection=True , fl=True , transforms=True )
- count = 1
- while count < len(tmp):
- count_r = (len(tmp) - count)
- x = tmp[count_r]
- tmp1 = x.split(':')
- tmp2 = tmp1[-1]
- cmds.select(clear=True)
- cmds.select( x )
- cmds.rename( tmp2 )
- count+=1
- def Export_Baker_Cmd():
- RenameBits()
- global Character_Stripped
- Character_Stripped = False
- HI_Top_Jnt= cmds.ls( ( '*' + MainJntToFind ) , type='joint' )
- if len(HI_Top_Jnt) <1:
- print 'Character Rig not found, possibly renamed or not in the scene?'
- else:
- pass #Find out if it has a parent? it should do!
- Parent_Test = cmds.listRelatives( HI_Top_Jnt[0] , parent=True )
- if Parent_Test is None:
- cmds.currentTime(1)
- print 'parent not found, baking as is on hips.'
- else:
- cmds.currentTime(1)
- cmds.parent( HI_Top_Jnt[0] , world = True)
- cmds.select(HI_Top_Jnt[0] , hi = True )
- tmp = cmds.ls( selection = True )
- for x in tmp:
- channels = [ 'tx' , 'ty' , 'tz' , 'rx' , 'ry' , 'rz' , 'sx' , 'sy' , 'sz' ]
- for chan in channels:
- cmds.setAttr( ( x + '.' + chan ) , k = True )
- cmds.select( clear = True )
- cmds.select( HI_Top_Jnt[0] , hi = True )
- Time_Start = cmds.playbackOptions(query=True , minTime=True)
- Time_End = cmds.playbackOptions(query=True , maxTime=True)
- cmds.bakeResults( time= ( Time_Start , Time_End) , simulation=True )
- cmds.select(HI_Top_Jnt[0] , hi=True )
- tmp = cmds.ls(selection=True)
- print tmp
- for x in tmp:
- cmds.select(clear=True)
- cmds.select(x)
- test_Joint = cmds.objectType(x)
- if test_Joint == 'joint':
- pass
- else:
- print 'deleting'
- print x
- cmds.delete(x)
- pass #Find the meshes!
- MeshList = cmds.ls( '*Mesh' , type='transform' )
- if MeshList is None:
- pass
- else:
- if len(MeshList)> 0:
- Parent_Test = cmds.listRelatives( MeshList[0] , parent=True )
- if Parent_Test is None:
- pass
- else:
- cmds.parent( MeshList[0] , world=True)
- cmds.select( MeshList[0] )
- cmds.select( hi=True )
- cmds.select( MeshList[0] , deselect=True )
- ALL_Bits_Shapes = cmds.ls( selection=True , shapes=True )
- for x in ALL_Bits_Shapes:
- cmds.select( clear=True )
- cmds.select( x )
- Transform = cmds.pickWalk(d='up')
- cmds.parent( Transform , world=True)
- cmds.delete(MeshList[0])
- else:
- print 'no meshes found?'
- pass #Cleanup time!
- pass # find all scale nodes and delete first!
- Time_Begin = cmds.playbackOptions(query=True , minTime=True)
- cmds.currentTime( Time_Begin )
- AllScaleNodes = cmds.ls( type = 'blendColors' )
- if len( AllScaleNodes ) > 0:
- cmds.delete( AllScaleNodes )
- ToDel = cmds.ls( '*Character_Rig')
- if len(ToDel) < 1:
- pass
- else:
- Parent_Test = cmds.listRelatives( ToDel[0] , parent=True )
- if Parent_Test is None:
- pass
- else:
- if ToDel is None:
- pass
- print 'nothing to delete'
- else:
- cmds.delete( Parent_Test[0] )
- cmds.currentTime(1)
- Character_Stripped = True
- tmpfile = cmds.file( sn=True , query=True)
- def FBXExport_Win():
- FBXExport_Win = "FBXExport_Win"
- if cmds.window('FBXExport_Win', exists=True):
- cmds.deleteUI('FBXExport_Win', window=True)
- cmds.windowPref( 'FBXExport_Win', remove=True )
- cmds.window( 'FBXExport_Win' , rtf=True , toolbox=True , widthHeight = Width_Height_Open )
- cmds.rowColumnLayout( 'FBXExport_MainWin' , numberOfColumns=1 , width = Width_Height_Open[0] , bgc= Drk_Grey )
- cmds.text( label= '-: FBX Exporter :- ' , align='center' , parent = 'FBXExport_MainWin' , width = Width_Height_Open[0] )
- cmds.rowColumnLayout( 'FBXExport_Btns' , numberOfColumns=3 , width = Width_Height_Open[0] , parent = 'FBXExport_MainWin' )
- cmds.button( 'FBXExport_Prop_AddBtn' , bgc = Grn_Btn_Col , label='Add' , width = (Width_Height_Open[0] / 3) , parent = 'FBXExport_Btns' , command = 'FBXExport_Win_ListUpdate_ADD()')
- cmds.button( 'FBXExport_Prop_RemBtn' , bgc = Yel_Btn_Col , label='Remove' , width = (Width_Height_Open[0] / 3) , parent = 'FBXExport_Btns' , command = 'FBXExport_Win_ListUpdate_REM()')
- cmds.button( 'FBXExport_Prop_ClrBtn' , bgc = Red_Btn_Col , label='Clear List' , width = (Width_Height_Open[0] / 3) , parent = 'FBXExport_Btns' , command = 'FBXExport_Win_ListUpdate_CLR()')
- cmds.rowColumnLayout( 'FBXExport_List_title' , numberOfColumns=1 , width = Width_Height_Open[0] , parent = 'FBXExport_MainWin' )
- cmds.button( 'FBXExport_Prop_PathBtn' , bgc= Lte_Grey , label='Export Meshs to :- (directory path )' , parent = 'FBXExport_List_title' , command = 'FBXExport_Win_ExportPathUpdate()' )
- cmds.setParent()
- cmds.scrollLayout( 'FBXExport_List_scroll' , parent = 'FBXExport_MainWin' , h= 10 , cr=True , vis=False)
- cmds.rowColumnLayout( 'FBXExport_List' , numberOfColumns=2 , width = Width_Height_Open[0] , parent = 'FBXExport_List_scroll' )
- cmds.setParent()
- cmds.rowColumnLayout( 'FBXExport_Btns_Export_Col' , numberOfColumns=1 , width = Width_Height_Open[0] , parent = 'FBXExport_MainWin' )
- cmds.text( label= '-: Export Art :- ' , parent = 'FBXExport_Btns_Export_Col' , align='center' , width = Width_Height_Open[0] )
- cmds.rowColumnLayout( 'FBXExport_Btns_Export_Col2' , numberOfColumns=2 , width = Width_Height_Open[0] , parent = 'FBXExport_Btns_Export_Col' )
- cmds.button( label='Prop / Mesh' , bgc= Art_Btn_Col , parent = 'FBXExport_Btns_Export_Col2' , width = ( Width_Height_Open[0] / 2 ) , command = 'Export_Opt_Prop()' )
- cmds.button( label='Character Rigged' , bgc= Art_Btn_Col , parent = 'FBXExport_Btns_Export_Col2' , width = ( Width_Height_Open[0] / 2 ) , command = 'Export_Opt_Char()' )
- cmds.setParent()
- cmds.text( label= '-: Export Animation :- ' , parent = 'FBXExport_Btns_Export_Col' , align='center' , width = Width_Height_Open[0] )
- cmds.rowColumnLayout( 'FBXExport_Btns_Export_Col3' , numberOfColumns=2 , width = Width_Height_Open[0] , parent = 'FBXExport_Btns_Export_Col' )
- cmds.button( label='Animated Mesh (rigid)' , bgc= Anims_Btn_Col , parent = 'FBXExport_Btns_Export_Col3' , width = ( Width_Height_Open[0] / 2 ) , command = 'Export_Opt_PropAnim()' )
- cmds.button( label='Char Joint Anim only' , bgc= Anims_Btn_Col , parent = 'FBXExport_Btns_Export_Col3' , width = ( Width_Height_Open[0] / 2 ) , command = 'Export_Opt_CharAnimNoMesh()' )
- cmds.button( label='Char and Mesh Anim' , bgc= Anims_Btn_Col , parent = 'FBXExport_Btns_Export_Col3' , width = ( Width_Height_Open[0] / 2 ) , command = 'Export_Opt_CharAnimAndMesh()' )
- cmds.setParent()
- cmds.text( label= '-: Misc :- ' , parent = 'FBXExport_Btns_Export_Col' , align='center' , width = Width_Height_Open[0] )
- cmds.rowColumnLayout( 'FBXExport_Btns_Export_Col4' , numberOfColumns=2 , width = Width_Height_Open[0] , parent = 'FBXExport_Btns_Export_Col' )
- cmds.setParent()
- #misc section..
- cmds.frameLayout( 'FBXExport_Prop_OptsTab' , label = 'extra options' , vis=True , cll=True , cl =True , parent='FBXExport_MainWin' , width = Width_Height_Open[0] )
- cmds.rowColumnLayout( 'FBXExport_Prop_OptsTab_col' , numberOfColumns=1 , width = Width_Height_Open[0] , parent = 'FBXExport_Prop_OptsTab' )
- cmds.checkBox( 'FBXExport_Check_Center' , label='Center Each Mesh to world zero and export.' , parent = 'FBXExport_Prop_OptsTab_col' , ann= 'Check this for all items to be batch exported to be moved to 0,0,0 before the process.' )
- # cmds.checkBox( 'FBXExport_Check_OptInForPath' , label='Use last known path automaticly for export' , parent = 'FBXExport_Prop_OptsTab_col' )
- cmds.intSliderGrp( 'FBXExport_MaxInfluences' , field=True , label='Vert Influences allowed' , max=4 , min=1 , v=3 )
- cmds.checkBox( 'FBXExport_Check_ReOpen' , label='Dont Reload the Maya file after export.' , ann= 'Check this to force the file to not reload (leaves you in the tmp broken file, good for debugging).' )
- # cmds.button( label='TagMainJnt' , bgc= Anims_Btn_Col , parent = 'FBXExport_Prop_OptsTab_col' , width = ( Width_Height_Open[0] / 2 ) , command = 'TagRig()' )
- #misc section thats hidden!
- cmds.frameLayout( 'FBXExport_Prop_OptsTab1' , label = 'extra options' , vis=False , cll=True , cl =True , parent='FBXExport_MainWin' , width = Width_Height_Open[0] )
- cmds.rowColumnLayout( 'FBXExport_Prop_OptsTab_col1' , numberOfColumns=1 , width = Width_Height_Open[0] , parent = 'FBXExport_Prop_OptsTab' )
- cmds.checkBox( 'FBXExport_Check_ISAnimated' , vis=False , label='Is an animated prop / mesh (without joints)' , parent = 'FBXExport_Prop_OptsTab_col1' , ann= 'Check this if the prop/mesh is animated.' )
- cmds.checkBox( 'FBXExport_Check_ExportAll' , vis=False , label='Export entire scene (Use scene name instead).' , parent = 'FBXExport_Prop_OptsTab_col1' , ann= 'Check this to export the entire scene rather than indidual FBX files.' )
- cmds.checkBox( 'FBXExport_Check_BodyParts' , vis=False , label='Meshs are Char/ BodyParts (no animation exported)' , parent = 'FBXExport_Prop_OptsTab_col1' , ann= 'Check this to export the Char/NPC body part meshes which use a different naming scheme...' )
- cmds.checkBox( 'FBXExport_Check_KeepAnimMeshes' , vis=False , label='Preserve Mesh data in Anim export.' , parent = 'FBXExport_Prop_OptsTab_col1' , ann= 'Check this if you dont want the meshes being deleted from the anim export (makes file larger).' )
- cmds.checkBox( 'FBXExport_Check_DontAddProp_Name' , v = 1 , vis= False , label='Use mesh name as filename (Otherwise m_ replaced with prop..).' , parent = 'FBXExport_Prop_OptsTab_col' , ann= 'Check this if you dont want the file name being changed from m_ to prop_ instead...' )
- cmds.text( 'FBXExport_ItemsTxtAll' , vis = False , label = '' , parent = 'FBXExport_Prop_OptsTab_col1' , width = ( Width_Height_Open[0] ) )
- cmds.showWindow( 'FBXExport_Win' )
- FBXExport_Win()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement