Exemplo n.º 1
0
def pickOutJoint(targets):

    import sgBFunction_dag

    for target in targets:
        targetH = sgBFunction_dag.getParents(target)
        targetH.append(target)
        children = cmds.listRelatives(target, c=1, ad=1)
        children.reverse()
        targetH += children

        oTargetH = []
        oTarget = om.MObject()
        for h in targetH:
            oTargetH.append(sgBFunction_dag.getMObject(h))
            if h == target: oTarget = oTargetH[-1]

        for i in range(len(oTargetH)):
            if oTarget == oTargetH[i]:
                fnChild = None
                fnParent = None
                fnTarget = om.MFnDagNode(oTargetH[i])
                if not i == 0:
                    fnParent = om.MFnDagNode(oTargetH[i - 1])
                if not i == len(oTargetH):
                    fnChild = om.MFnDagNode(oTargetH[i + 1])

                if fnChild:
                    if fnParent:
                        cmds.parent(fnChild.fullPathName(),
                                    fnParent.fullPathName())
                    else:
                        cmds.parent(fnChild.fullPathName(), w=1)

                cmds.delete(fnTarget.fullPathName())
Exemplo n.º 2
0
def exportSgKeyData( targetTransformNodes, startFrame, endFrame, step, folderPath=None, exportByMatrix=False, *args ):
    
    import sgBFunction_scene
    import copy
    
    if step < 0.05:
        cmds.error( "Step Must be larger then %.f." % step )
    
    sgBFunction_base.autoLoadPlugin( "sgBDataCmd" )
    if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgKeyDataPath()
    sgBFunction_fileAndPath.makeFolder( folderPath )
    sgBFunction_fileAndPath.removeChildFiles( folderPath )
    
    targetTransformNodeParents = []
    for transformNode in targetTransformNodes:
        targetTransformNodeParents += sgBFunction_dag.getParents( transformNode )
        targetTransformNodeParents.append( transformNode )
    targetTransformNodeParents = list( set( targetTransformNodeParents ) )
    
    sgBFunction_scene.exportTransformData( targetTransformNodeParents, folderPath )
    
    cmds.sgBDataCmd_key( targetTransformNodes, se=1, folderPath= folderPath, ebm=exportByMatrix )
    
    cuTime = copy.copy( startFrame )
    
    while cuTime <= endFrame+1:
        cmds.currentTime( cuTime )
        cmds.sgBDataCmd_key( write=1 )
        cuTime += step

    cmds.sgBDataCmd_key( ee=1 )
Exemplo n.º 3
0
def pickOutJoint( targets ):
    
    import sgBFunction_dag
    
    for target in targets:
        targetH = sgBFunction_dag.getParents( target )
        targetH.append( target )
        children = cmds.listRelatives( target, c=1, ad=1 )
        children.reverse()
        targetH += children
        
        oTargetH = []
        oTarget = om.MObject()
        for h in targetH:
            oTargetH.append( sgBFunction_dag.getMObject( h ) )
            if h == target: oTarget = oTargetH[-1]
        
        for i in range( len( oTargetH ) ):
            if oTarget == oTargetH[i]:
                fnChild = None
                fnParent = None
                fnTarget = om.MFnDagNode( oTargetH[i] )
                if not i == 0:
                    fnParent = om.MFnDagNode( oTargetH[i-1] )
                if not i == len( oTargetH ):
                    fnChild = om.MFnDagNode( oTargetH[i+1] )
                
                if fnChild:
                    if fnParent:
                        cmds.parent( fnChild.fullPathName(), fnParent.fullPathName() )
                    else:
                        cmds.parent( fnChild.fullPathName(), w=1 )
                
                cmds.delete( fnTarget.fullPathName() )
Exemplo n.º 4
0
def mirrorRig(transformNode):

    import sgBModel_data
    import sgBFunction_dag

    sgBModel_data.mirrorRigCheckedTargets = []
    targetParents = sgBFunction_dag.getParents(transformNode)

    targetParents.append(transformNode)

    for i in range(len(targetParents)):
        mirrorConnect(targetParents[i])
Exemplo n.º 5
0
def mirrorRig( transformNode ):

    import sgBModel_data
    import sgBFunction_dag
    
    sgBModel_data.mirrorRigCheckedTargets = []
    targetParents = sgBFunction_dag.getParents( transformNode )
    
    targetParents.append( transformNode )
    
    for i in range( len( targetParents ) ):
        mirrorConnect( targetParents[i] )
Exemplo n.º 6
0
def export_transformsBake(targets, fileName=None):

    import sgBFunction_fileAndPath
    import sgBFunction_dag
    import cPickle

    if not fileName:
        scenePath = cmds.file(q=1, sceneName=1)
        if scenePath:
            sceneFolder = '/'.join(scenePath.split('/')[:-1])
            fileName = sceneFolder + '/transformsBake/bakeFile.txt'
        else:
            fileName = sgBFunction_fileAndPath.getMayaDocPath(
            ) + '/transformsBake/bakeFile.txt'
    defaultExportTransformBakePath = sgBFunction_fileAndPath.getMayaDocPath(
    ) + '/defaultExportTransformsBake.txt'

    exTargets = []
    for target in targets:
        if cmds.nodeType(target) != 'transform': continue
        cloneH = sgBFunction_dag.getParents(target)
        cloneH.append(cmds.ls(target, l=1)[0])
        exTargets += cloneH

    exTargets = list(set(exTargets))
    exTargets.sort()
    exTargetMtxs = [[] for i in range(len(exTargets))]

    minFrame = cmds.playbackOptions(q=1, min=1)
    maxFrame = cmds.playbackOptions(q=1, max=1)
    unit = cmds.currentUnit(q=1, time=1)

    for t in range(int(minFrame), int(maxFrame + 1)):
        cmds.currentTime(t)
        for i in range(len(exTargets)):
            exTargetMtx = cmds.getAttr(exTargets[i] + '.m')
            exTargetMtxs[i].append(exTargetMtx)

    fileName = sgBFunction_fileAndPath.makeFile(fileName)
    f = open(fileName, 'w')
    datas = [unit, minFrame, maxFrame]
    for i in range(len(exTargets)):
        extargetName = exTargets[i].replace(':', '_')
        datas.append([extargetName, exTargetMtxs[i]])
    cPickle.dump(datas, f)
    f.close()

    f = open(defaultExportTransformBakePath, 'w')
    cPickle.dump(fileName, f)
    f.close()

    print "Export Path : ", fileName
Exemplo n.º 7
0
def export_transformsBake( targets, fileName=None ):
    
    import sgBFunction_fileAndPath
    import sgBFunction_dag
    import cPickle

    if not fileName:
        scenePath = cmds.file( q=1, sceneName=1 )
        if scenePath:
            sceneFolder = '/'.join( scenePath.split( '/' )[:-1] )
            fileName = sceneFolder + '/transformsBake/bakeFile.txt'
        else:
            fileName = sgBFunction_fileAndPath.getMayaDocPath()+ '/transformsBake/bakeFile.txt'
    defaultExportTransformBakePath = sgBFunction_fileAndPath.getMayaDocPath() + '/defaultExportTransformsBake.txt'
    
    exTargets = []
    for target in targets:
        if cmds.nodeType( target ) != 'transform': continue
        cloneH = sgBFunction_dag.getParents( target )
        cloneH.append( cmds.ls( target, l=1 )[0] )
        exTargets += cloneH

    exTargets = list( set( exTargets ) )
    exTargets.sort()
    exTargetMtxs = [ [] for i in range( len( exTargets ) ) ]
    
    minFrame = cmds.playbackOptions( q=1, min=1 )
    maxFrame = cmds.playbackOptions( q=1, max=1 )
    unit     = cmds.currentUnit( q=1, time=1 )
    
    for t in range( int( minFrame ), int( maxFrame+1 ) ):
        cmds.currentTime( t )
        for i in range( len( exTargets ) ):
            exTargetMtx = cmds.getAttr( exTargets[i] + '.m' )
            exTargetMtxs[i].append( exTargetMtx )
    
    fileName = sgBFunction_fileAndPath.makeFile( fileName )
    f = open( fileName, 'w' )
    datas = [ unit, minFrame, maxFrame ]
    for i in range( len( exTargets ) ):
        extargetName = exTargets[i].replace( ':', '_' )
        datas.append( [ extargetName, exTargetMtxs[i] ] )
    cPickle.dump( datas, f )
    f.close()
    
    f = open( defaultExportTransformBakePath, 'w' )
    cPickle.dump( fileName, f )
    f.close()
    
    print "Export Path : ", fileName
Exemplo n.º 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 )
Exemplo n.º 9
0
def exportSgKeyData(targetTransformNodes,
                    startFrame,
                    endFrame,
                    step,
                    folderPath=None,
                    exportByMatrix=False,
                    *args):

    import sgBFunction_scene
    import copy

    if step < 0.05:
        cmds.error("Step Must be larger then %.f." % step)

    sgBFunction_base.autoLoadPlugin("sgBDataCmd")
    if not folderPath:
        folderPath = sgBFunction_fileAndPath.getDefaultSgKeyDataPath()
    sgBFunction_fileAndPath.makeFolder(folderPath)
    sgBFunction_fileAndPath.removeChildFiles(folderPath)

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

    sgBFunction_scene.exportTransformData(targetTransformNodeParents,
                                          folderPath)

    cmds.sgBDataCmd_key(targetTransformNodes,
                        se=1,
                        folderPath=folderPath,
                        ebm=exportByMatrix)

    cuTime = copy.copy(startFrame)

    while cuTime <= endFrame + 1:
        cmds.currentTime(cuTime)
        cmds.sgBDataCmd_key(write=1)
        cuTime += step

    cmds.sgBDataCmd_key(ee=1)
Exemplo n.º 10
0
def createControlAbleJoint(topJoint):

    import sgBFunction_dag

    parents = sgBFunction_dag.getParents(topJoint)

    targetParent = None
    if parents: targetParent = parents[-1]

    children = sgBFunction_dag.getDirectChildren(topJoint)

    firstJnt = None
    if targetParent:
        cmds.select(targetParent)
        firstJnt = cmds.joint()
    else:
        firstJnt = cmds.createNode('joint')

    dcmp = cmds.createNode('decomposeMatrix')
    cmds.connectAttr(topJoint + '.m', dcmp + '.imat')
    cmds.connectAttr(dcmp + '.ot', firstJnt + '.t')
    cmds.connectAttr(dcmp + '.or', firstJnt + '.jo')
    cmds.connectAttr(dcmp + '.os', firstJnt + '.s')
    cmds.connectAttr(dcmp + '.osh', firstJnt + '.sh')

    jnts = [firstJnt]
    for child in children:
        cmds.select(firstJnt)
        cuJnt = cmds.joint()
        dcmp = cmds.createNode('decomposeMatrix')
        cmds.connectAttr(child + '.m', dcmp + '.imat')
        cmds.connectAttr(dcmp + '.ot', cuJnt + '.t')
        cmds.connectAttr(dcmp + '.or', cuJnt + '.jo')
        cmds.connectAttr(dcmp + '.os', cuJnt + '.s')
        cmds.connectAttr(dcmp + '.osh', cuJnt + '.sh')
        firstJnt = cuJnt
        jnts.append(firstJnt)

    return jnts
Exemplo n.º 11
0
def createControlAbleJoint( topJoint ):
    
    import sgBFunction_dag
    
    parents = sgBFunction_dag.getParents( topJoint )
    
    targetParent = None
    if parents: targetParent = parents[-1]
    
    children = sgBFunction_dag.getDirectChildren( topJoint )
    
    firstJnt = None
    if targetParent:
        cmds.select( targetParent )
        firstJnt = cmds.joint()
    else:
        firstJnt = cmds.createNode( 'joint' )
    
    dcmp = cmds.createNode( 'decomposeMatrix' )
    cmds.connectAttr( topJoint+'.m', dcmp+'.imat' )
    cmds.connectAttr( dcmp+'.ot', firstJnt+'.t' )
    cmds.connectAttr( dcmp+'.or', firstJnt+'.jo' )
    cmds.connectAttr( dcmp+'.os', firstJnt+'.s' )
    cmds.connectAttr( dcmp+'.osh', firstJnt+'.sh' )
    
    jnts = [firstJnt]
    for child in children:
        cmds.select( firstJnt )
        cuJnt = cmds.joint()
        dcmp = cmds.createNode( 'decomposeMatrix' )
        cmds.connectAttr( child+'.m', dcmp+'.imat' )
        cmds.connectAttr( dcmp+'.ot', cuJnt+'.t' )
        cmds.connectAttr( dcmp+'.or', cuJnt+'.jo' )
        cmds.connectAttr( dcmp+'.os', cuJnt+'.s' )
        cmds.connectAttr( dcmp+'.osh', cuJnt+'.sh' )
        firstJnt = cuJnt
        jnts.append( firstJnt )
        
    return jnts
Exemplo n.º 12
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)
Exemplo n.º 13
0
    def getExportTargets(*args):

        exportTargets = []

        def searchIsRight(tr, searchForType, searchFor, splitName):
            if splitName: compairTr = tr.split(splitName)[-1]
            else: compairTr = tr
            if searchForType == 0 and compairTr.find(searchFor) != -1:
                return True
            elif searchForType == 1 and compairTr[:len(searchFor
                                                       )] == searchFor:
                return True
            elif searchForType == 2 and compairTr[-len(searchFor
                                                       ):] == searchFor:
                return True

        exportType = WinA_Cmd.getExportType()
        if exportType == 0:

            meshObjs = sgBFunction_selection.getMeshObjectFromGroup(
                cmds.ls(sl=1))

            parents = []
            for sel in meshObjs:
                parents += sgBFunction_dag.getParents(sel)
            parents = list(set(parents))
            targetParents = []
            for parent in parents:
                if not sgBFunction_dag.itHasTransformConnection(parent):
                    continue
                targetParents.append(parent)

            for meshObj in meshObjs:
                if not sgBFunction_dag.itHasTransformConnection(meshObj):
                    continue
                exportTargets.append(meshObj)
            exportTargets += targetParents

        elif exportType == 1:
            searchFor = cmds.textField(WinA_Global.searchFor_txf, q=1, tx=1)
            searchForType = WinA_Cmd.getSearchForType()
            splitName = WinA_Cmd.getSplitName()
            if not searchFor: cmds.error("Check Search For String")

            targets = []
            for tr in cmds.ls(tr=1):
                if searchIsRight(tr, searchForType, searchFor, splitName):
                    targets.append(tr)

            parents = []
            for target in targets:
                parents += sgBFunction_dag.getParents(target)
            parents = list(set(parents))

            targetParents = []
            for parent in parents:
                if not sgBFunction_dag.itHasTransformConnection(parent):
                    continue
                targetParents.append(parent)

            meshObjs = sgBFunction_selection.getMeshObjectFromGroup(targets)
            for meshObj in meshObjs:
                if not sgBFunction_dag.itHasTransformConnection(meshObj):
                    continue
                exportTargets.append(meshObj)
            exportTargets += targetParents

        elif exportType == 2:
            searchFor = cmds.textField(WinA_Global.searchFor_txf, q=1, tx=1)
            searchForType = WinA_Cmd.getSearchForType()
            splitName = WinA_Cmd.getSplitName()
            if not searchFor: cmds.error("Check Search For String")

            targets = []
            trChildren = cmds.listRelatives(cmds.ls(sl=1),
                                            c=1,
                                            ad=1,
                                            f=1,
                                            type='transform')
            trChildren += cmds.ls(sl=1)
            for tr in trChildren:
                if searchIsRight(tr, searchForType, searchFor, splitName):
                    targets.append(tr)

            parents = []
            for target in targets:
                parents += sgBFunction_dag.getParents(target)
            parents = list(set(parents))

            targetParents = []
            for parent in parents:
                if not sgBFunction_dag.itHasTransformConnection(parent):
                    continue
                targetParents.append(parent)

            meshObjs = sgBFunction_selection.getMeshObjectFromGroup(targets)
            for meshObj in meshObjs:
                if not sgBFunction_dag.itHasTransformConnection(meshObj):
                    continue
                exportTargets.append(meshObj)
            exportTargets += targetParents

        return exportTargets
Exemplo n.º 14
0
    def getExportTargets( *args ):
        
        exportTargets = []
        
        def searchIsRight( tr, searchForType, searchFor, splitName ):
            if splitName: compairTr = tr.split( splitName )[-1]
            else: compairTr = tr
            if searchForType == 0 and compairTr.find( searchFor ) != -1:
                return True
            elif searchForType == 1 and compairTr[ :len(searchFor) ] == searchFor:
                return True
            elif searchForType == 2 and compairTr[ -len( searchFor ): ] == searchFor:
                return True
                
        exportType = WinA_Cmd.getExportType()
        if exportType == 0:
            
            meshObjs = sgBFunction_selection.getMeshObjectFromGroup( cmds.ls( sl=1 ) )

            parents = []
            for sel in meshObjs:
                parents += sgBFunction_dag.getParents( sel )
            parents = list( set( parents ) )
            targetParents = []
            for parent in parents:
                if not sgBFunction_dag.itHasTransformConnection( parent ): continue
                targetParents.append( parent )

            for meshObj in meshObjs:
                if not sgBFunction_dag.itHasTransformConnection( meshObj ): continue
                exportTargets.append( meshObj )
            exportTargets += targetParents;
                
        elif exportType == 1:
            searchFor = cmds.textField( WinA_Global.searchFor_txf, q=1, tx=1 )
            searchForType = WinA_Cmd.getSearchForType()
            splitName = WinA_Cmd.getSplitName()
            if not searchFor: cmds.error( "Check Search For String" )
            
            targets = []
            for tr in cmds.ls( tr=1 ):
                if searchIsRight( tr, searchForType, searchFor, splitName ):
                    targets.append( tr )
            
            parents = []
            for target in targets:
                parents += sgBFunction_dag.getParents( target )
            parents = list( set( parents ) )
            
            targetParents = []
            for parent in parents:
                if not sgBFunction_dag.itHasTransformConnection( parent ): continue
                targetParents.append( parent )
            
            meshObjs = sgBFunction_selection.getMeshObjectFromGroup( targets )
            for meshObj in meshObjs:
                if not sgBFunction_dag.itHasTransformConnection( meshObj ): continue
                exportTargets.append( meshObj )
            exportTargets += targetParents;
                
        elif exportType == 2:
            searchFor = cmds.textField( WinA_Global.searchFor_txf, q=1, tx=1 )
            searchForType = WinA_Cmd.getSearchForType()
            splitName = WinA_Cmd.getSplitName()
            if not searchFor: cmds.error( "Check Search For String" )
            
            targets = []
            trChildren = cmds.listRelatives( cmds.ls( sl=1 ), c=1, ad=1, f=1, type='transform' )
            trChildren += cmds.ls( sl=1 )
            for tr in trChildren:
                if searchIsRight( tr, searchForType, searchFor, splitName ):
                    targets.append( tr )
            
            parents = []
            for target in targets:
                parents += sgBFunction_dag.getParents( target )
            parents = list( set( parents ) )
            
            targetParents = []
            for parent in parents:
                if not sgBFunction_dag.itHasTransformConnection( parent ): continue
                targetParents.append( parent )
            
            meshObjs = sgBFunction_selection.getMeshObjectFromGroup( targets )
            for meshObj in meshObjs:
                if not sgBFunction_dag.itHasTransformConnection( meshObj ): continue
                exportTargets.append( meshObj )
            exportTargets += targetParents;
            
        return exportTargets