def moveFile( srcPath, targetPath ):
    
    launchPath = ''
    for path in sys.path:
        
        path = path.replace( '\\', '/' )
        
        if not os.path.isdir( path ):
            continue
        dirList = os.listdir( path )
        if 'sgFunctionStandaloneLaunch' in dirList:
            launchPath = path+'/sgFunctionStandaloneLaunch/sgMoveFile.py'
    
    moveFileInfo = sgModelFileAndPath.getLocusCommPackagePrefsPath() + '/sgStandalone/moveFile.txt'
    sysPathInfoPath = sgModelFileAndPath.getLocusCommPackagePrefsPath() + '/sgStandalone/sysPath.txt'
    
    sgFunctionFileAndPath.makeFile( sysPathInfoPath, False )
    sgFunctionFileAndPath.makeFile( moveFileInfo, False )
    
    f = open( sysPathInfoPath, 'w' )
    cPickle.dump( sys.path, f )
    f.close()
    
    f = open( moveFileInfo, 'w' )
    cPickle.dump( [srcPath, targetPath], f )
    f.close()
    
    mel.eval( 'system( "start %s %s" )' %( sgModelFileAndPath.getMayaPyPath(), launchPath ) )
Beispiel #2
0
def exportCharactersAnimationToFile(topGrps, filePath, start, end):

    chBakeDatas = []
    bakeFilePaths = []
    for topGrp in topGrps:
        chBakeData = CharacterBakeData(topGrp)
        chBakeDatas.append(chBakeData)
        bakeFilePaths.append(filePath + '/' +
                             chBakeData.namespace.replace(':', '_') +
                             '.sgCjbake')

    import copy
    frame = copy.copy(start)
    while (frame < end):
        cmds.currentTime(frame)
        frame += 1.0
        for chBakeData in chBakeDatas:
            chBakeData.appendValue()

    for i in range(len(bakeFilePaths)):
        import sgFunctionFileAndPath
        sgFunctionFileAndPath.makeFile(bakeFilePaths[i], False)
        f = open(bakeFilePaths[i], 'w')
        cPickle.dump(chBakeDatas[i], f)
        f.close()
Beispiel #3
0
def moveFile(srcPath, targetPath):

    launchPath = ''
    for path in sys.path:

        path = path.replace('\\', '/')

        if not os.path.isdir(path):
            continue
        dirList = os.listdir(path)
        if 'sgFunctionStandaloneLaunch' in dirList:
            launchPath = path + '/sgFunctionStandaloneLaunch/sgMoveFile.py'

    moveFileInfo = sgModelFileAndPath.getLocusCommPackagePrefsPath(
    ) + '/sgStandalone/moveFile.txt'
    sysPathInfoPath = sgModelFileAndPath.getLocusCommPackagePrefsPath(
    ) + '/sgStandalone/sysPath.txt'

    sgFunctionFileAndPath.makeFile(sysPathInfoPath, False)
    sgFunctionFileAndPath.makeFile(moveFileInfo, False)

    f = open(sysPathInfoPath, 'w')
    cPickle.dump(sys.path, f)
    f.close()

    f = open(moveFileInfo, 'w')
    cPickle.dump([srcPath, targetPath], f)
    f.close()

    mel.eval('system( "start %s %s" )' %
             (sgModelFileAndPath.getMayaPyPath(), launchPath))
Beispiel #4
0
def makeFile( fileName, data =None ):
    
    import sgFunctionFileAndPath
    path = 'D:/makeFile/' + fileName + '.txt'
    sgFunctionFileAndPath.makeFile( path )
    
    if data:
        f = open( path, 'w' )
        f.write( data )
        f.close()
Beispiel #5
0
    def exportKeyData(self, topGrp, filePath, ns=''):

        import sgModelDg
        import sgFunctionFileAndPath

        children = cmds.listRelatives(topGrp, c=1, ad=1, type='transform')
        children.append(topGrp)

        self.namespace = ns
        self.attrAndData = []
        for child in children:
            try:
                keyAttrs = cmds.listAttr(child, k=1)
            except:
                continue
            if not keyAttrs: continue
            try:
                keyAttrs += cmds.listAttr(child, cb=1)
            except:
                pass
            for attr in keyAttrs:
                if not cmds.ls(child + '.' + attr): continue
                value = cmds.getAttr(child + '.' + attr)
                origName = child.replace(ns, '')
                self.attrAndData.append([origName + '.' + attr, value, None])

                cons = cmds.listConnections(child + '.' + attr,
                                            s=1,
                                            d=0,
                                            type='animCurve')
                if not cons: continue

                animCurveDataInst = sgModelDg.AnimCurveData(cons[0])
                self.attrAndData[-1][2] = animCurveDataInst

        sgFunctionFileAndPath.makeFile(filePath, False)
        f = open(filePath, 'w')
        cPickle.dump(self.attrAndData, f)
        f.close()
Beispiel #6
0
import maya.cmds as cmds
import sgModelUI
import cPickle, shutil

import sgModelFileAndPath
import sgFunctionFileAndPath

settingInfoPath = sgModelFileAndPath.getLocusCommPackagePrefsPath(
) + "/reloadPluginInfo.txt"
tempPluginTestPath = sgModelFileAndPath.getLocusCommPackagePrefsPath(
) + '/tempFile/pluginTest.mb'
sgFunctionFileAndPath.makeFile(settingInfoPath, False)
sgFunctionFileAndPath.makeFile(tempPluginTestPath, False)


class TwoTextFiels:
    def __init__(self, firstString, secondString, w=120, h=22):

        self.firstString = firstString
        self.secondString = secondString
        self.width = w
        self.height = h

    def create(self):

        form = cmds.formLayout()

        txt_first = cmds.text(l=self.firstString,
                              al='right',
                              w=self.width,
                              h=self.height)
Beispiel #7
0
def exportBakeData( targets, startFrame, endFrame, cachePath = '' ):
    
    transformBakePath = cachePath + '/transformBake.cPickle'
    
    targets = sgModelConvert.convertFullPathNames( targets )
    trObjs = cmds.listRelatives( targets, c=1, ad=1, type='transform', f=1 )
    if not trObjs: trObjs = []
    trObjs += targets
    
    trParents = []
    for trObj in trObjs:
        parents = sgModelDag.getParents( trObj )
        trParents += parents
    
    trs = list( set( trObjs + trParents ) )
    
    trs.sort()
    
    namespaces = []
    filePaths  = []
    cacheBodyPaths = []
    
    namespaceIndices = []
    for tr in trs:
        if not cmds.reference( tr, q=1, inr=1 ):
            namespaceIndices.append( None )
            continue
        
        namespace = cmds.referenceQuery( tr, ns=1 )
        filePath = cmds.reference( tr, q=1, filename =1 ).split( '{' )[0]
        
        cacheBodyPath = '.'.join( filePath.split( '.' )[:-1] ) + '_cachebody.' + filePath.split( '.' )[-1]

        if not os.path.exists( cacheBodyPath ):
            cacheBodyPath = ''

        if not namespace in namespaces:
            print "appended namespace :", namespace
            namespaces.append( namespace )
            filePaths.append( filePath )
            cacheBodyPaths.append( cacheBodyPath )
        
        namespaceIndex = namespaces.index( namespace )
        namespaceIndices.append( namespaceIndex )

    parentList = []
    objectList = []
    
    shapes = []
    for i in range( len( trs ) ):
        tr = trs[i]
        trParent = cmds.listRelatives( tr, p=1, f=1 )
        trMtx = cmds.getAttr( tr+'.m' )
        trPiv = cmds.xform( tr, q=1, os=1, piv=1 )[:3]
        
        listAttrs = cmds.listAttr( tr, k=1 )
        attrInfoList = []
        for attr in listAttrs:
            if not cmds.attributeQuery( attr, node=tr, ex=1 ): continue
            if cmds.listConnections( tr+'.'+ attr, s=1, d=0 ):
                animCurves = cmds.listConnections( tr+'.'+ attr, s=1, d=0, type='animCurve' )
                if animCurves:
                    attrInfoList.append( [attr, sgModelDg.AnimCurveData( animCurves[0] )] )
                else:
                    attrInfoList.append( [attr, []] )
            else:
                parentAttrs = cmds.attributeQuery( attr, node=tr, listParent = 1 )
                if parentAttrs:
                    if cmds.listConnections( tr+'.'+parentAttrs[0], s=1, d=0 ):
                        attrInfoList.append( [attr, []] )

        if trParent: trParent = trParent[0]
        if trParent in parentList:
            parentIndex= parentList.index( trParent )
        else:
            parentIndex = -1
        
        objectList.append( [ namespaceIndices[i], parentIndex, tr, trMtx, trPiv, attrInfoList ] )
        parentList.append( tr )
        
        shape = sgModelDag.getShape( tr )
        if shape: shapes.append( shape )
    
    timeUnit = cmds.currentUnit( q=1, time=1 )
    dataForExport = [ namespaces, filePaths, cacheBodyPaths, objectList, timeUnit ]

    deformedShapes = sgModelDag.getDeformedObjects( shapes )

    if deformedShapes:
        def setKeyframeBakeTargets( *args ):
            cuTime = cmds.currentTime( q=1 )
            
            for i in range( len(objectList) ):
                for j in range( len( objectList[i][5] ) ):
                    attr = objectList[i][5][j][0]
                    info = objectList[i][5][j][1]
                    if type( info ) != type( [] ): continue
                    tr = objectList[i][2]
                    value = cmds.getAttr( tr+'.' + attr )
                    objectList[i][5][j][1].append( [ cuTime, value ] )
        
        callbackId = om.MEventMessage().addEventCallback( 'timeChanged', setKeyframeBakeTargets )
        cmds.select( deformedShapes )
        sgFunctionFileAndPath.makeFolder( cachePath )
        mel.eval( 'doCreateGeometryCache 6 { "3", "%s", "%s", "OneFile", "1", "%s","1","","0", "export", "0", "1", "1","0","0","mcc","0" };' %( startFrame, endFrame, cachePath ) )
        om.MMessage().removeCallback( callbackId )

    transformBakePath = sgFunctionFileAndPath.makeFile( transformBakePath, False )
    f = open( transformBakePath, 'w' )
    cPickle.dump( dataForExport, f )
    f.close()
    
    return transformBakePath
Beispiel #8
0
import maya.cmds as cmds
import sgModelUI
import cPickle, shutil

import sgModelFileAndPath
import sgFunctionFileAndPath
        
settingInfoPath = sgModelFileAndPath.getLocusCommPackagePrefsPath() + "/reloadPluginInfo.txt"
tempPluginTestPath = sgModelFileAndPath.getLocusCommPackagePrefsPath() + '/tempFile/pluginTest.mb'
sgFunctionFileAndPath.makeFile( settingInfoPath, False )
sgFunctionFileAndPath.makeFile( tempPluginTestPath, False )




class TwoTextFiels:
    
    def __init__(self, firstString, secondString, w=120, h=22 ):
        
        self.firstString = firstString
        self.secondString = secondString
        self.width = w
        self.height = h
    
    
    def create(self):
        
        form = cmds.formLayout()
        
        txt_first  = cmds.text( l=self.firstString, al='right', w= self.width, h=self.height )
        txt_second = cmds.text( l=self.secondString, al='right', w= self.width, h=self.height )
Beispiel #9
0
f = open( sysPathInfoPath, 'r' )
sysPaths = cPickle.load( f )
f.close()

f = open( makeScenePath, 'r' )
scenePath = f.read()
f.close()

f = open( addCommandPath, 'r' )
addCommand = f.read()
f.close()


for path in sysPaths:
    if not path in sys.path:
        sys.path.append( path )

import sgFunctionFileAndPath

maya.standalone.initialize( name='python' )
sgFunctionFileAndPath.makeFile( scenePath, False )


cmds.file( rename=scenePath )
try:
    exec( addCommand )
except:
    print "--------------------------------------"
    print "AddCommand is not acceptable"
    print "--------------------------------------"
cmds.file( f=1, save=1,  options="v=0;", type="mayaBinary" )
    if not path in sys.path:
        sys.path.append(path)

import sgFunctionFileAndPath
import sgRigAttribute
import sgModelDg

f = open(standaloneInfoPath, 'r')
scenePaths, bakeInfoPaths = cPickle.load(f)
f.close()

for i in range(len(scenePaths)):

    scenePath = scenePaths[i]
    bakeInfoPath = bakeInfoPaths[i]
    sgFunctionFileAndPath.makeFile(scenePath, False)

    cmds.file(f=1, new=1)

    f = open(bakeInfoPath, 'r')
    bakeTargetList = cPickle.load(f)
    f.close()

    bakeInfoPath = bakeInfoPath.replace('\\', '/')
    sceneInfoPath = '/'.join(
        bakeInfoPath.split('/')[:-1]) + '/sceneInfo.sceneInfo'

    f = open(sceneInfoPath, 'r')
    timeUnit, minTime, maxTime = cPickle.load(f)
    f.close()
Beispiel #11
0
def exportBakedData( selTargets, cachePath, startFrame, endFrame, offsetStart =-1, offsetEnd=1 ):

    defaultCachePath = sgModelFileAndPath.getDefaultCachePath()

    cachePath = cachePath.replace( '\\', '/' )
    defaultCachePath = defaultCachePath.replace( '\\', '/' )

    refNodes = []

    selTargetChildren = cmds.listRelatives( selTargets, c=1, ad=1, type='transform' )
    selTargetChildren += selTargets

    for selTarget in selTargetChildren:
        if not cmds.referenceQuery( selTarget, inr=1 ): continue
        refNode = cmds.referenceQuery( selTarget, rfn=1 )
        if refNode in refNodes: continue
        refNodes.append( refNode )

    namespaceArray = []
    fileNameArray  = []
    bakeTargetListArray = []
    deformedShapesArray = []
    for refNode in refNodes:
        namespace, fileName, bakeTargetList, deformedShapes = getExportBakeData( refNode, selTargets )

        namespaceArray.append( namespace )
        fileNameArray.append( fileName )
        bakeTargetListArray.append( bakeTargetList )
        deformedShapesArray += deformedShapes

    def setKeyframeBakeTargets( *args ):
        for k in range( len( refNodes ) ):
            bakeTargetList = bakeTargetListArray[ k ]
            
            for i in range( len( bakeTargetList ) ):
                for j in range( len( bakeTargetList[i][3] ) ):
                    attr = bakeTargetList[i][3][j][0]
                    info = bakeTargetList[i][3][j][1]
                    if not info.connectionExists: continue
                    '''
                    if cmds.currentTime( q=1 ) == 30:
                        print "setKeyframeTarget : ", bakeTargetList[i][0] + '.' + attr'''
                    info.appendKeyframeData()

    sgFunctionFileAndPath.makeFolder( cachePath )
    sgFunctionFileAndPath.makeFolder( defaultCachePath )
    if deformedShapesArray:
        callbackId = om.MEventMessage().addEventCallback( 'timeChanged', setKeyframeBakeTargets )
        cmds.select( deformedShapesArray )
        mel.eval( 'doCreateGeometryCache 6 { "3", "%s", "%s", "OneFile", "1", "%s","1","","0", "export", "0", "1", "1","0","0","mcc","0" };' %( startFrame + offsetStart, endFrame + offsetEnd, defaultCachePath ) )
        om.MMessage().removeCallback( callbackId )
    else:
        callbackId = om.MEventMessage().addEventCallback( 'timeChanged', setKeyframeBakeTargets )
        cmds.select( deformedShapes )
        for frame in range( startFrame+offsetStart, endFrame+offsetEnd + 1 ):
            cmds.currentTime( frame )
        om.MMessage().removeCallback( callbackId )

    animCurvesPaths = []
    bakeInfoPaths  = []
    for i in range( len( namespaceArray ) ):

        namespace = namespaceArray[i]
        fileName  = fileNameArray[i]
        bakeTargetList = bakeTargetListArray[i]
        bakeInfoPath  = cachePath + '/' + namespace + '.bakeInfo'
        assetInfoPath = cachePath + '/' + namespace + '.assetInfo'
        animCurvesPath = cachePath + '/' + namespace + '.ma'
        sgFunctionFileAndPath.makeFile( bakeInfoPath, False )
        sgFunctionFileAndPath.makeFile( assetInfoPath, False )

        animCurvesPaths.append( animCurvesPath )
        bakeInfoPaths.append( bakeInfoPath )

        f = open( bakeInfoPath, 'w' )
        cPickle.dump( bakeTargetList, f )
        f.close()

        f = open( assetInfoPath, 'w' )
        f.write( fileName )
        f.close()

        def makeAnimCurveScene():
            animCurves = []
            for k in range( len( bakeTargetList ) ):
                #print "bakeTrargetList : ", bakeTargetList[k]
                tr = bakeTargetList[k][0]
                
                for j in range( len( bakeTargetList[k][3] ) ):
                    attr = bakeTargetList[k][3][j][0]
                    info = bakeTargetList[k][3][j][1]
                    animCurve = info.createAnimCurve()
                    #animCurve = cmds.rename( animCurve, 'sceneBake_animCurve_for_%s' %( tr.split( '|' )[-1]+'_'+attr ) )
                    sgRigAttribute.addAttr( animCurve, ln='bakeTargetAttrName', dt='string' )
                    cmds.setAttr( animCurve+'.bakeTargetAttrName', tr+'.'+attr, type='string' )
                    animCurves.append( animCurve )
            
            if not animCurves: animCurves = [cmds.createNode( 'animCurveUU' )]
            cmds.select( animCurves )
            cmds.file( animCurvesPath, force=1, options="v=0;", typ="mayaAscii", es=1 )
            cmds.delete( animCurves )
        
        #makeAnimCurveScene()

    import sgFunctionStandalone
    standaloneInfoPath = 'C:/Users/skkim/Documents/maya/LocusCommPackagePrefs/sgStandalone/sgFunctionSceneBake2_makeScene.txt'
    sgFunctionStandalone.sgFunctionSceneBake2_makeScene( animCurvesPaths, bakeInfoPaths, standaloneInfoPath )

    timeUnit = cmds.currentUnit( q=1, time=1 )
    minTime  = startFrame
    maxTime  = endFrame
    
    sceneInfo = [ timeUnit, minTime, maxTime ]
    
    sceneInfoPath = cachePath + '/sceneInfo.sceneInfo'
    sgFunctionFileAndPath.makeFile( sceneInfoPath, False )
    
    f = open( sceneInfoPath, 'w' )
    cPickle.dump( sceneInfo, f )
    f.close()
    
    print "export : ", defaultCachePath, cachePath
    sgFunctionStandalone.moveFile( defaultCachePath, cachePath )
    print "------------- scene bake"