Пример #1
0
    def __init__(self, *args, **kwargs):
        super(MayaSelectWatcher, self).__init__(*args, **kwargs)
        if self.current_instance:
            raise Exception("A MayaSelectedWatcher object already exists.")

        # 创建条件捕捉对象
        self.event_message = openmaya.MEventMessage()
        self.event_message.addEventCallback("SelectionChanged",
                                            self.on_something_selected)
        MayaSelectWatcher.current_instance = self
Пример #2
0
    def __init__(self, duration=20, slot=None):
        """

        Args:
            duration: during time, in minutes.
            slot: a function which will be executed when time up

        Returns:

        """
        self.__duration_msec = duration * SecPerMin * MsecPerSec
        self.__slot = slot
        self.__timer = None

        self.event_message = OpenMaya.MEventMessage()
        self.event_message.addEventCallback("SceneSaved", self.restart)
Пример #3
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
Пример #4
0
def appendEventCallback(event, ptrFunction):

    eventMessage = om.MEventMessage()
    callback = eventMessage.addEventCallback(event, ptrFunction)
    sgBModel_message.eventMessageCallbacks.append(callback)
Пример #5
0
def removeAllEventCallback():

    eventMessage = om.MEventMessage()
    for callbackId in sgBModel_message.eventMessageCallbacks:
        eventMessage.removeCallback(callbackId)
    sgBModel_message.eventMessageCallbacks = []
Пример #6
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"
Пример #7
0
import rebuild
import nHair
import volume
import cutting
import convert
import grooming
import guide
import bake
import functions

import volumeHairTool

from functools import partial
import maya.OpenMaya as om

mEvent = om.MEventMessage()

import volumeHairTool.basecode as basecode


class Cmd:
    def __init__(self):

        pass

    def getBaseMesh(self, pointer):

        return cmds.textField(pointer._baseMesh, q=1, tx=1)

    def getSurfaceShapes(self, pointer):
Пример #8
0
def exportKeyAndCacheData(keyTransformNodes,
                          cacheTransformNodes,
                          keyFolderPath,
                          cacheFolderPath,
                          startFrame,
                          endFrame,
                          step,
                          exportByMatrix=False,
                          exportType='mcc',
                          *args):

    import maya.mel as mel
    import sgBFunction_selection
    import maya.OpenMaya as om
    import sgBFunction_scene

    sgBFunction_base.autoLoadPlugin("sgBDataCmd")

    keyFolderPath = keyFolderPath.replace('\\', '/')
    cacheFolderPath = cacheFolderPath.replace('\\', '/')

    def exportKeyEachFrame(*args):
        cmds.sgBDataCmd_key(write=1)

    connectedTransforms = sgBFunction_selection.getTransformConnectedObjectsFromGroup(
        keyTransformNodes)
    deformedTransforms = sgBFunction_selection.getDeformedObjectsFromGroup(
        cacheTransformNodes)

    if deformedTransforms and connectedTransforms:
        sgBFunction_fileAndPath.makeFolder(keyFolderPath)
        sgBFunction_fileAndPath.makeFolder(cacheFolderPath)

        targetTransformNodeParents = []
        for transformNode in connectedTransforms:
            targetTransformNodeParents += sgBFunction_dag.getParents(
                transformNode)
            targetTransformNodeParents.append(transformNode)
        targetTransformNodeParents = list(set(targetTransformNodeParents))

        sgBFunction_scene.exportTransformData(targetTransformNodeParents,
                                              keyFolderPath)

        cmds.sgBDataCmd_key(connectedTransforms,
                            se=1,
                            folderPath=keyFolderPath,
                            ebm=exportByMatrix)
        callbackId = om.MEventMessage().addEventCallback(
            'timeChanged', exportKeyEachFrame)
        cmds.select(deformedTransforms)
        mel.eval(
            'doCreateGeometryCache 6 { "3", "%s", "%s", "OneFile", "1", "%s","1","","0", "export", "0", "%s", "1","0","0","%s","0" };'
            % (startFrame, endFrame, cacheFolderPath, step, exportType))
        om.MMessage().removeCallback(callbackId)
        cmds.sgBDataCmd_key(ee=1)

    elif deformedTransforms and not connectedTransforms:
        exportCacheData(deformedTransforms, startFrame, endFrame, step,
                        cacheFolderPath, exportType)

    elif not deformedTransforms and connectedTransforms:
        exportSgKeyData(connectedTransforms, startFrame, endFrame, step,
                        keyFolderPath, exportByMatrix)