예제 #1
2
def setSmartKey(time=None, animCurves=None, select=True, insert=True, replace=True, addTo=False):
    
    if not time: time   = animMod.getTimelineTime()    
    getFrom             = "timeline"
    
    if not animCurves:
        getCurves  = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom    = getCurves[1]
    
    
    if animCurves and getFrom != "timeline": 
        cmds.setKeyframe(animCurves, time=time, insert=insert)
        if select: cmds.selectKey(animCurves, replace=replace, addTo=addTo, time=time)
        
    else:
        objects = animMod.getObjsSel()
        if objects:
            
            channelboxSelObjs = animMod.channelBoxSel()
            if channelboxSelObjs:
                #objsAttrs     = ["%s.%s"%(loopObj, loopChannelboxSel) for loopObj in objects for loopChannelboxSel in channelboxSel]
                         
                #key selected attributes in the channelbox
                for n, loopObjAttr in enumerate(channelboxSelObjs):
                    prevKey       = cmds.findKeyframe(loopObjAttr, time=(time,time), which="previous")
                    tangentType   = cmds.keyTangent(loopObjAttr, query=True, outTangentType=True, time=(prevKey,prevKey)) 
               
                    if not tangentType: #if there is no key 
                        tangentType = cmds.keyTangent(query=True, g=True, outTangentType=True)
                        inTangentType  = tangentType[0].replace("fixed", "auto").replace("step", "auto")
                        outTangentType = tangentType[0].replace("fixed", "auto")
                        cmds.setKeyframe(loopObjAttr, time=time, insert=False, shape=False, inTangentType=inTangentType, outTangentType=outTangentType)
                        continue
                    
                    inTangentType  = tangentType[0].replace("fixed", "auto").replace("step", "auto")
                    outTangentType = tangentType[0].replace("fixed", "auto")
                
                    cmds.setKeyframe(loopObjAttr, time=time, insert=insert, shape=False, inTangentType=inTangentType, outTangentType=outTangentType)
                    
            else:
                #allChannels   = animMod.getAllChannels(objects)
                #objAttrs      = ["%s.%s"%(objects[n], loopAttr) for n, loopObj in enumerate(allChannels) for loopAttr in loopObj]
                prevKeys      = [cmds.findKeyframe(obj, time=(time,time), which="previous") for obj in objects]
                tangentTypes  = [cmds.keyTangent(obj, query=True, outTangentType=True, time=(prevKeys[n],prevKeys[n])) for n, obj in enumerate(objects)]
                #prevKeys      = [cmds.findKeyframe(obj, time=(time,time), which="previous") for obj in objAttrs]
                #tangentTypes  = [cmds.keyTangent(obj, query=True, outTangentType=True, time=(prevKeys[n],prevKeys[n])) for n, obj in enumerate(objAttrs)]
                #key all atributes
                cmds.setKeyframe(objects, time=time, insert=insert, shape=False) 
                #cmds.setKeyframe(objAttrs, time=time, insert=insert, shape=False)    
                            
                if insert: #will force create key if there is no key
                    for n, loopTangent in enumerate(tangentTypes):
                        if not loopTangent:
                            cmds.setKeyframe(objects[n], time=time, insert=False, shape=False)
예제 #2
1
    def flowAround(self, frames=2, excludeCurrKey=False):

        getCurves = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom = getCurves[1]

        if animCurves:
            # if getFrom == "graphEditor":
            keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
            tangentType = "flow"
            time = None

            # animMod.expandKeySelection(frames)

            index = animMod.getTarget("keysIndexSel", animCurves, getFrom)
            indexTimes = animMod.getTarget("keyIndexTimes", animCurves, getFrom)

            # expand selection
            for n, loopCurve in enumerate(index):
                for x in xrange(frames):
                    if loopCurve[0] >= 1:
                        loopCurve.insert(0, loopCurve[0] - 1)
                    if loopCurve[-1] < indexTimes[n][-1]:
                        loopCurve.append(loopCurve[-1] + 1)

                # if excludeCurrKey:

            self.applyTangent(animCurves, tangentType, getFrom, time, index)

            # select back keys
            if keysSel:
                cmds.selectKey(clear=True)
                for n, aCurve in enumerate(animCurves):
                    for key in keysSel[n]:
                        cmds.selectKey(aCurve, addTo=True, time=(key, key))
예제 #3
0
 def spaceSwitch(self, args, all=False, mode="token"):
     
     cmds.refresh(suspend=True)
     
     if mode == "token":    switch = self.spaceSwitchToken
     elif mode == "custom": switch = self.spaceSwitchCustom        
     
     objects     = args[0] 
     attr        = args[1]    
     currSel     = cmds.ls(selection=True)      
     currFrame   = cmds.currentTime(query=True)
     getCurves   = animMod.getAnimCurves()
     animCurves  = getCurves[0]
     getFrom     = getCurves[1]         
     
     if animCurves:
         if all: keysSel = animMod.getTarget("keyTimes", animCurves, getFrom)
         else:   keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
         
         keysSel = utilMod.mergeLists(keysSel)    
         if keysSel == []:
              keysSel = [currFrame]   
     else:
         keysSel = [currFrame]
     
     frames = keysSel
     
     for loopObj in currSel:
         if loopObj not in objects: continue
         if not cmds.objExists("%s.%s"%(loopObj, attr)):continue
     
         animMod.createDummyKey([loopObj])
         
         getCurves       = animMod.getAnimCurves(True)
         animCurves      = getCurves[0]
         
         animMod.deleteDummyKey([loopObj])     
         
         for loopFrame in frames:                   
             cmds.currentTime(loopFrame)  
             
             matrix     = cmds.xform(loopObj, query=True, ws=True, matrix=True)
             rotation    = cmds.xform(loopObj, query=True, ws=True, rotation=True)
                           
             switch(loopObj, args)                                
             cmds.xform(loopObj, ws=True, matrix=matrix)  
             cmds.xform(loopObj, ws=True, rotation=rotation)
             
                     
         animMod.eulerFilterCurve(animCurves) 
         
                
     cmds.currentTime(currFrame)
     cmds.refresh(suspend=False)
예제 #4
0
파일: align.py 프로젝트: Italic-/maya-prefs
 def alignSelection(self, translate=True, rotate=True, all=False):
     
     selection   = cmds.ls(selection=True)
     
     if len(selection) < 2: 
         cmds.warning("You need to select at least 2 objects.")
         return
     
     sourceObjs      = selection[0:-1]
     targetObj       = selection[-1]
     frames          = None
     currFrame       = cmds.currentTime(query=True) 
     getCurves       = animMod.getAnimCurves()
     animCurves      = getCurves[0]
     getFrom         = getCurves[1]
     showProgress    = all
     
     
     if animCurves:
         if all: keysSel = animMod.getTarget("keyTimes", animCurves, getFrom)
         else:   keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
         
         frames  = utilMod.mergeLists(keysSel)
         
         if frames == []:
              frames = [currFrame]   
     else:
         frames = [currFrame]
     
     self.align(sourceObjs, targetObj, frames, translate, rotate, showProgress, selectSorceObjs=True)
예제 #5
0
    def copyAnimation(self, range="selected", *args):    
        cmds.waitCursor(state=True)
        
        if range == "all":
                        
            getCurves    = animMod.getAnimCurves()
            animCurves   = getCurves[0]
            animData = animMod.getAnimData(animCurves, showProgress=True)
        else:
            animData = animMod.getAnimData(showProgress=True)
            
        aToolsMod.saveInfoWithUser("copyPasteAnim", "animData", animData)  

        if cmds.window("remapNamespacesWindow", query=True, exists=True): self.remapNamespaces()
        
        cmds.waitCursor(state=False)  
예제 #6
0
 def applyTickColor(self, special=True, *args):
     
     getCurves   = animMod.getAnimCurves()
     animCurves  = getCurves[0]
     getFrom     = getCurves[1]
     
     keysSel     = animMod.getTarget("keysSel", animCurves, getFrom)
     
     if animCurves:
         
          for n, loopCurve in enumerate(animCurves):
             time = [(loopTime,loopTime) for loopTime in keysSel[n]]
                 
             for loopTime in time:
                 #keycolor
                 cmds.keyframe(loopCurve ,edit=True,time=loopTime, tickDrawSpecial=special)
예제 #7
0
    def applyTickColor(self, special=True, *args):

        getCurves   = animMod.getAnimCurves()
        animCurves  = getCurves[0]
        getFrom     = getCurves[1]

        keysSel     = animMod.getTarget("keysSel", animCurves, getFrom)

        if animCurves:

             for n, loopCurve in enumerate(animCurves):
                time = [(loopTime,loopTime) for loopTime in keysSel[n]]

                for loopTime in time:
                    #keycolor
                    cmds.keyframe(loopCurve ,edit=True,time=loopTime, tickDrawSpecial=special)
예제 #8
0
def selectOnlyKeyedObjects():

    getCurves = animMod.getAnimCurves()
    animCurves = getCurves[0]
    getFrom = getCurves[1]

    if animCurves:

        keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
        objects = animMod.getTarget("", animCurves, getFrom)[0]
        selObjs = []

        for n, loopObj in enumerate(objects):
            if len(keysSel[n]) > 0:
                if not loopObj in selObjs:
                    selObjs.append(loopObj)

        if len(selObjs) > 0: cmds.select(selObjs, replace=True)
예제 #9
0
def selectOnlyKeyedObjects():
    
    getCurves   = animMod.getAnimCurves()
    animCurves  = getCurves[0]
    getFrom     = getCurves[1]
    
    if animCurves:
    
        keysSel      = animMod.getTarget("keysSel", animCurves, getFrom)
        objects      = animMod.getTarget("", animCurves, getFrom)[0]
        selObjs      = []

        
        for n, loopObj in enumerate(objects):
            if len(keysSel[n]) > 0:
                if not loopObj in selObjs:
                    selObjs.append(loopObj)
                    
        if len(selObjs) > 0: cmds.select(selObjs, replace=True)
예제 #10
0
def cropTimelineAnimation():

    getCurves = animMod.getAnimCurves()
    animCurves = getCurves[0]
    getFrom = getCurves[1]
    range = animMod.getTimelineRange()

    if animCurves:
        keyTimes = animMod.getTarget("keyTimes", animCurves, getFrom)

        for n, aCurve in enumerate(animCurves):

            firstKey = keyTimes[n][0]
            lastKey = keyTimes[n][-1]

            if range[0] >= firstKey:
                cmds.cutKey(aCurve, time=(firstKey, range[0] - 1), clear=True)

            if range[1] <= lastKey:
                cmds.cutKey(aCurve, time=(range[1], lastKey), clear=True)
예제 #11
0
def cropTimelineAnimation():
    
    getCurves  = animMod.getAnimCurves()
    animCurves = getCurves[0]
    getFrom    = getCurves[1] 
    range      = animMod.getTimelineRange()  
        
    if animCurves:        
        keyTimes            = animMod.getTarget("keyTimes", animCurves, getFrom)
    
        for n, aCurve in enumerate(animCurves):
            
            firstKey = keyTimes[n][0]
            lastKey = keyTimes[n][-1]
            
           
            if range[0] >= firstKey: 
                cmds.cutKey(aCurve, time=(firstKey, range[0]-1), clear=True)
                
            if range[1] <= lastKey: 
                cmds.cutKey(aCurve, time=(range[1], lastKey), clear=True)        
예제 #12
0
    def alignSelection(self, translate=True, rotate=True, all=False):

        selection = cmds.ls(selection=True)

        if len(selection) < 2:
            cmds.warning("You need to select at least 2 objects.")
            return

        sourceObjs = selection[0:-1]
        targetObj = selection[-1]
        frames = None
        currFrame = cmds.currentTime(query=True)
        getCurves = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom = getCurves[1]
        showProgress = all

        if animCurves:
            if all:
                keysSel = animMod.getTarget("keyTimes", animCurves, getFrom)
            else:
                keysSel = animMod.getTarget("keysSel", animCurves, getFrom)

            frames = utilMod.mergeLists(keysSel)

            if frames == []:
                frames = [currFrame]
        else:
            frames = [currFrame]

        self.align(sourceObjs,
                   targetObj,
                   frames,
                   translate,
                   rotate,
                   showProgress,
                   selectSorceObjs=True)
예제 #13
0
    def setTween(self, percent, *args):

        #utilMod.timer("s")

        G.TM_lastTweenCommand = "self.setTween(%s)" % percent

        getCurves = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom = getCurves[1]

        if animCurves:
            status = "aTools - Tween Machine..."
            utilMod.startProgressBar(status)
            totalSteps = len(animCurves)
            firstStep = 0
            thisStep = 0
            estimatedTime = None
            startChrono = None

            cmds.waitCursor(state=True)
            cmds.refresh(suspend=True)

            keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
            keyTimes = animMod.getTarget("keyTimes", animCurves)
            timelineTime = None
            #keysSelMerged   = utilMod.mergeLists(keysSel)

            # reverse order to get ease in and out smoothly
            if 0 < percent <= 50 or percent == 100:
                for loopVal in keysSel:
                    loopVal.reverse()

            #utilMod.timer()
            """
            if len(keysSelMerged) == 0:
                if not timelineTime: timelineTime = [animMod.getTimelineTime()]
                cmds.setKeyframe(animCurves, time=timelineTime[0])
            elif len(keysSelMerged) == 1:
                cmds.setKeyframe(animCurves, time=keysSelMerged[0])
            """

            for thisStep, loopCurve in enumerate(animCurves):

                if cmds.progressBar(G.progBar, query=True, isCancelled=True):
                    utilMod.setProgressBar(endProgress=True)
                    break

                startChrono = utilMod.chronoStart(startChrono, firstStep,
                                                  thisStep, totalSteps,
                                                  estimatedTime, status)

                if not keysSel[thisStep]:
                    if not timelineTime:
                        timelineTime = [animMod.getTimelineTime()]
                    time = timelineTime
                else:
                    time = [(loopTime, loopTime)
                            for loopTime in keysSel[thisStep]]
                    # if all keys selected, use timeline time instead
                    if len(time) == len(keyTimes[thisStep]):
                        if not timelineTime:
                            timelineTime = [animMod.getTimelineTime()]
                        time = timelineTime

                for loopTime in time:

                    prevKeyTime = cmds.findKeyframe(loopCurve,
                                                    time=loopTime,
                                                    which="previous")
                    nextKeyTime = cmds.findKeyframe(loopCurve,
                                                    time=loopTime,
                                                    which="next")

                    if prevKeyTime == nextKeyTime and prevKeyTime != loopTime[
                            0] and percent != "linear_next" and percent != "linear_prev":  # if there is no previous or next key and at least one key
                        cmds.setKeyframe(loopCurve, time=loopTime)

                    elif prevKeyTime != time[0]:

                        if percent == "linear_prev":

                            prevKeyTime = nextKeyTime
                            nextKeyTime = cmds.findKeyframe(loopCurve,
                                                            time=(prevKeyTime,
                                                                  prevKeyTime),
                                                            which="next")
                            prevKeyVal = cmds.keyframe(loopCurve,
                                                       query=True,
                                                       time=(prevKeyTime,
                                                             prevKeyTime),
                                                       valueChange=True)[0]
                            nextKeyVal = cmds.keyframe(loopCurve,
                                                       query=True,
                                                       time=(nextKeyTime,
                                                             nextKeyTime),
                                                       valueChange=True)[0]

                            if nextKeyTime == prevKeyTime:
                                value = prevKeyVal
                            else:
                                value = prevKeyVal + (
                                    (nextKeyVal - prevKeyVal) /
                                    (nextKeyTime - prevKeyTime) *
                                    (loopTime[0] - prevKeyTime))

                        elif percent == "linear_next":

                            nextKeyTime = prevKeyTime
                            prevKeyTime = cmds.findKeyframe(loopCurve,
                                                            time=(nextKeyTime,
                                                                  nextKeyTime),
                                                            which="previous")
                            prevKeyVal = cmds.keyframe(loopCurve,
                                                       query=True,
                                                       time=(prevKeyTime,
                                                             prevKeyTime),
                                                       valueChange=True)[0]
                            nextKeyVal = cmds.keyframe(loopCurve,
                                                       query=True,
                                                       time=(nextKeyTime,
                                                             nextKeyTime),
                                                       valueChange=True)[0]

                            if nextKeyTime == prevKeyTime:
                                value = prevKeyVal
                            else:
                                value = prevKeyVal + (
                                    (nextKeyVal - prevKeyVal) /
                                    (nextKeyTime - prevKeyTime) *
                                    (loopTime[0] - prevKeyTime))

                        else:

                            animMod.eulerFilterCurve([loopCurve])

                            prevKeyVal = cmds.keyframe(loopCurve,
                                                       query=True,
                                                       time=(prevKeyTime,
                                                             prevKeyTime),
                                                       valueChange=True)[0]
                            nextKeyVal = cmds.keyframe(loopCurve,
                                                       query=True,
                                                       time=(nextKeyTime,
                                                             nextKeyTime),
                                                       valueChange=True)[0]

                            #print "prevKeyVal", prevKeyVal, nextKeyVal

                            #if prevKeyVal == nextKeyVal:
                            #if not time[0] in keysSel[thisStep]: cmds.setKeyframe(loopCurve, time=loopTime)
                            #continue

                            if percent == "linear":
                                value = prevKeyVal + (
                                    (nextKeyVal - prevKeyVal) /
                                    (nextKeyTime - prevKeyTime) *
                                    (loopTime[0] - prevKeyTime))
                            else:
                                value = ((nextKeyVal - prevKeyVal) / 100. *
                                         percent) + prevKeyVal

                        tangentType = cmds.keyTangent(loopCurve,
                                                      query=True,
                                                      outTangentType=True,
                                                      time=(prevKeyTime,
                                                            prevKeyTime))[0]
                        inTangentType = tangentType.replace("fixed",
                                                            "auto").replace(
                                                                "step", "auto")
                        outTangentType = tangentType.replace("fixed", "auto")

                        if not time[0] in keysSel[thisStep]:
                            cmds.setKeyframe(loopCurve, time=loopTime)

                        cmds.keyframe(loopCurve,
                                      edit=True,
                                      time=loopTime,
                                      valueChange=value)
                        cmds.keyTangent(loopCurve,
                                        edit=True,
                                        time=loopTime,
                                        inTangentType=inTangentType,
                                        outTangentType=outTangentType)
                        #keycolor
                        if 1 <= percent <= 99 or percent == "linear":
                            cmds.keyframe(
                                loopCurve,
                                edit=True,
                                time=loopTime,
                                tickDrawSpecial=self.getColoredKeys())

                    if getFrom == "graphEditor":
                        #curvesToSelect.append([loopCurve, loopTime])
                        cmds.selectKey(loopCurve, addTo=True, time=loopTime)

                estimatedTime = utilMod.chronoEnd(startChrono, firstStep,
                                                  thisStep, totalSteps)

            #utilMod.timer()
            """
            #APPLY
            if len(curvesToKey) > 0: cmds.setKeyframe(curvesToKey)

            for loopVar in curvesToValue:
                cmds.keyframe(loopVar[0], edit=True, time=loopVar[1], valueChange=loopVar[2])
                cmds.keyTangent(loopVar[0], edit=True, time=loopVar[1], inTangentType=loopVar[3], outTangentType=loopVar[4])

            for loopVar in curvesToColor:  cmds.keyframe(loopVar[0], edit=True, time=loopVar[1], tickDrawSpecial=self.getColoredKeys())
            for loopVar in curvesToSelect: cmds.selectKey(loopVar[0], addTo=True, time=loopVar[1])
            """

            cmds.refresh(suspend=False)
            cmds.waitCursor(state=False)
            utilMod.setProgressBar(endProgress=True)
예제 #14
0
def smartSnapKeys():

    getCurves = animMod.getAnimCurves()
    animCurves = getCurves[0]

    if not animCurves or len(animCurves) == 0: return

    getFrom = getCurves[1]
    keyTimes = animMod.getTarget("keyTimes", animCurves, getFrom)
    keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
    hasDecimalKeys = False

    for loopKey in utilMod.mergeLists(keysSel):
        if loopKey != round(loopKey) > 0:
            hasDecimalKeys = True
            break

    if not hasDecimalKeys: return

    keyTangentsType = animMod.getTarget("keyTangentsType", animCurves, getFrom)
    firstStep = 0
    totalSteps = len(animCurves)
    estimatedTime = None
    status = "aTools - Smart Snap Curves..."
    startChrono = None
    utilMod.startProgressBar(status)

    for thisStep, loopCurve in enumerate(animCurves):

        startChrono = utilMod.chronoStart(startChrono, firstStep, thisStep,
                                          totalSteps, estimatedTime, status)

        if None in [keyTimes[thisStep], keysSel[thisStep]]: continue

        stepKeys = [
            loopKey for nn, loopKey in enumerate(keyTimes[thisStep])
            if loopKey != round(loopKey) and loopKey in keysSel[thisStep]
            and keyTangentsType[thisStep][nn][1] == "step"
        ]
        linearKeys = [
            loopKey for nn, loopKey in enumerate(keyTimes[thisStep])
            if loopKey != round(loopKey) and loopKey in keysSel[thisStep]
            and keyTangentsType[thisStep][nn][1] == "linear"
        ]
        decimalKeys = [
            loopKey for nn, loopKey in enumerate(keyTimes[thisStep])
            if loopKey != round(loopKey) and loopKey in keysSel[thisStep]
            and loopKey not in stepKeys + linearKeys
        ]

        for loopKey in stepKeys:
            cmds.snapKey(loopCurve, time=(loopKey, loopKey))
        for loopKey in linearKeys:
            cmds.snapKey(loopCurve, time=(loopKey, loopKey))

        if len(decimalKeys) == 0: continue

        if not getFrom:
            if cmds.keyframe(query=True, selected=True) != None:
                getFrom = "graphEditor"

        #inLinearKeys    = [round(loopKey) for nn, loopKey in enumerate(keyTimes[thisStep]) if keyTangentsType[thisStep][nn][0] == "linear"]
        #outLinearKeys   = [round(loopKey) for nn, loopKey in enumerate(keyTimes[thisStep]) if keyTangentsType[thisStep][nn][1] == "linear"]
        createKeys = list(set([round(loopKey) for loopKey in decimalKeys]))
        selectKeys = []

        #print "inlinearKeys", inLinearKeys, outLinearKeys

        if getFrom == "graphEditor":
            selectKeys = list(
                set([
                    round(loopKey) for loopKey in keysSel[thisStep]
                    if round(loopKey) in createKeys
                ]))

        for loopKey in createKeys:
            cmds.setKeyframe(loopCurve, time=(loopKey, loopKey), insert=True)
        for loopKey in selectKeys:
            cmds.selectKey(loopCurve, addTo=True, time=(loopKey, loopKey))
        for loopKey in decimalKeys:
            cmds.cutKey(loopCurve, time=(loopKey, loopKey))
        #for loopKey in outLinearKeys:   cmds.keyTangent(loopCurve, edit=True, time=(loopKey, loopKey), outTangentType="linear")
        #for loopKey in inLinearKeys:    cmds.keyTangent(loopCurve, edit=True, time=(loopKey, loopKey), inTangentType="linear")

        estimatedTime = utilMod.chronoEnd(startChrono, firstStep, thisStep,
                                          totalSteps)

    utilMod.setProgressBar(endProgress=True)
예제 #15
0
def eulerFilterSelection():
    getCurves = animMod.getAnimCurves()
    animCurves = getCurves[0]

    animMod.eulerFilterCurve(animCurves)
예제 #16
0
    def align(self,
              sourceObjs,
              targetObj,
              frames=None,
              translate=True,
              rotate=True,
              showProgress=False,
              selectSorceObjs=False):

        if not sourceObjs or not targetObj: return

        cmds.refresh(suspend=True)

        currFrame = cmds.currentTime(query=True)
        constraints = []
        setValues = []
        modes = []
        status = "aTools - Aligning nodes..."

        if translate:
            modes.append({"mode": "translate", "constrain": "pointConstraint"})
        if rotate:
            modes.append({"mode": "rotate", "constrain": "orientConstraint"})

        if showProgress: utilMod.startProgressBar(status)

        if not frames:
            getCurves = animMod.getAnimCurves()
            animCurves = getCurves[0]
            getFrom = getCurves[1]

            if animCurves:
                keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
                frames = utilMod.mergeLists(keysSel)

                if frames == []:
                    frames = [currFrame]
            else:
                frames = [currFrame]

        if showProgress:
            totalSteps = len(sourceObjs + frames)
            firstStep = 0
            thisStep = 0
            estimatedTime = None
            startChrono = None

        #get values
        for thisStep, loopSourceObj in enumerate(sourceObjs):

            if showProgress:
                startChrono = utilMod.chronoStart(startChrono, firstStep,
                                                  thisStep, totalSteps,
                                                  estimatedTime, status)

            setValues.append({"modes": [], "values": [], "skips": []})

            for loopMode in modes:

                mode = loopMode["mode"]
                constrainType = loopMode["constrain"]

                allAttrs = cmds.listAttr(loopSourceObj,
                                         settable=True,
                                         keyable=True)
                skip = [
                    loopXyz for loopXyz in ["x", "y", "z"]
                    if "%s%s" % (mode, loopXyz.upper()) not in allAttrs
                ]
                contrainFn = eval("cmds.%s" % constrainType)

                with G.aToolsBar.createAToolsNode:
                    constraints.append(
                        contrainFn(targetObj, loopSourceObj, skip=skip)[0])

                setValues[-1]["modes"].append(mode)
                setValues[-1]["values"].append([
                    cmds.getAttr("%s.%s" % (loopSourceObj, mode),
                                 time=loopKey)[0] for loopKey in frames
                ])
                setValues[-1]["skips"].append(skip)

            if showProgress:
                estimatedTime = utilMod.chronoEnd(startChrono, firstStep,
                                                  thisStep, totalSteps)

        #del constraints
        for loopConstrain in constraints:
            cmds.delete(loopConstrain)

        for n, loopKey in enumerate(frames):

            if showProgress:
                thisStep = thisStep + n + 1
                startChrono = utilMod.chronoStart(startChrono, firstStep,
                                                  thisStep, totalSteps,
                                                  estimatedTime, status)

            for nn, loopSourceObj in enumerate(sourceObjs):
                loopSetValue = setValues[nn]
                values = loopSetValue["values"]
                skips = loopSetValue["skips"]

                for nnn, loopMode in enumerate(modes):
                    mode = loopMode["mode"]
                    xyz = [
                        loopXyz for loopXyz in ["x", "y", "z"]
                        if loopXyz not in skips[nnn]
                    ]

                    for nnnn, loopXyz in enumerate(xyz):
                        attr = "%s%s" % (mode, loopXyz.upper())
                        value = values[nnn][n][nnnn]

                        if len(frames) > 1:
                            cmds.setKeyframe(loopSourceObj,
                                             attribute=attr,
                                             time=(loopKey, loopKey),
                                             value=value)

                        if currFrame == loopKey:
                            cmds.setAttr("%s.%s" % (loopSourceObj, attr),
                                         value)

                #euler filter
                if n == len(frames) - 1 and rotate:
                    animCurves = utilMod.mergeLists([
                        cmds.keyframe(loopSourceObj, query=True, name=True)
                        for loopSourceObj in sourceObjs
                    ])
                    animMod.eulerFilterCurve(animCurves)

            if showProgress:
                estimatedTime = utilMod.chronoEnd(startChrono, firstStep,
                                                  thisStep, totalSteps)

        if showProgress: utilMod.setProgressBar(endProgress=True)
        if selectSorceObjs: cmds.select(sourceObjs)
        cmds.refresh(suspend=False)
예제 #17
0
 def paste(self, type="onlyKeys"):
     
     cmds.refresh(suspend=True)        
         
     selObjects      = utilMod.getNameSpace(self.selection)[1]  
     self.locators   = []
     
     if self.targetObj != "world":
         #CREATE
         self.locatorGroup = animMod.group(name=self.locatorGroupName)   
          
         for n, loopObj in enumerate(self.sourceObjs):
             
             nameSpace       = utilMod.getNameSpace([loopObj])
             loopSelName     = "%s_%s"%(nameSpace[0][0], nameSpace[1][0]) 
             locatorName     = "fakeConstrain_%s"%loopSelName 
             
             locator = animMod.createNull(locatorName)            
             self.locators.append(locator)
             with G.aToolsBar.createAToolsNode: cmds.parent(locator, self.locatorGroup)   
            
         self.locators.append(self.locatorGroup)
     
     currFrame   = cmds.currentTime(query=True)
     getCurves   = animMod.getAnimCurves()
     animCurves  = getCurves[0]
     getFrom     = getCurves[1]         
     
     if animCurves:
         keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
         keysSel = utilMod.mergeLists(keysSel)    
         if keysSel == []:
              keysSel = [currFrame]   
     else:
         keysSel = [currFrame]
     
     frames = keysSel
     
     if type == "allFrames":
         frameRange = animMod.getTimelineRange(float=False)
         frames = list(range(int(frameRange[0]),int(frameRange[1])))
         
     if self.targetObj != "world":
         G.aToolsBar.align.align([self.locatorGroup], self.targetObj, frames=frames)
                     
     for n, loopObj in enumerate(self.sourceObjs):
              
         matrix     = self.copyCache[n]         
         
         if self.targetObj != "world":
             cmds.xform(self.locators[n], matrix=matrix)
                     
             G.aToolsBar.align.align([loopObj], self.locators[n], frames=frames, showProgress=True)
             
         else:
             for loopFrame in frames:
                 cmds.currentTime(loopFrame)          
                 cmds.xform(loopObj, ws=True, matrix=matrix)
             
             cmds.currentTime(currFrame)
                     
         for loopFrame in frames:
             for loopAttr in ["translate", "rotate"]:
                 breakdown = (loopFrame not in keysSel)
                 cmds.keyframe(loopObj, edit=True, attribute=loopAttr, time=(loopFrame, loopFrame), breakdown=breakdown)
     
         
     if self.targetObj != "world":
         self.clearLocators()     
         cmds.select(self.selection) 
     
     cmds.refresh(suspend=False)
예제 #18
0
def setSmartKey(time=None,
                animCurves=None,
                select=True,
                insert=True,
                replace=True,
                addTo=False):

    if not time: time = animMod.getTimelineTime()
    getFrom = "timeline"

    if not animCurves:
        getCurves = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom = getCurves[1]

    if animCurves and getFrom != "timeline":
        cmds.setKeyframe(animCurves, time=time, insert=insert)
        if select:
            cmds.selectKey(animCurves, replace=replace, addTo=addTo, time=time)

    else:
        objects = animMod.getObjsSel()
        if objects:

            channelboxSelObjs = animMod.channelBoxSel()
            if channelboxSelObjs:
                #objsAttrs     = ["%s.%s"%(loopObj, loopChannelboxSel) for loopObj in objects for loopChannelboxSel in channelboxSel]

                #key selected attributes in the channelbox
                for n, loopObjAttr in enumerate(channelboxSelObjs):
                    prevKey = cmds.findKeyframe(loopObjAttr,
                                                time=(time, time),
                                                which="previous")
                    tangentType = cmds.keyTangent(loopObjAttr,
                                                  query=True,
                                                  outTangentType=True,
                                                  time=(prevKey, prevKey))

                    if not tangentType:  #if there is no key
                        tangentType = cmds.keyTangent(query=True,
                                                      g=True,
                                                      outTangentType=True)
                        inTangentType = tangentType[0].replace(
                            "fixed", "auto").replace("step", "auto")
                        outTangentType = tangentType[0].replace(
                            "fixed", "auto")
                        cmds.setKeyframe(loopObjAttr,
                                         time=time,
                                         insert=False,
                                         shape=False,
                                         inTangentType=inTangentType,
                                         outTangentType=outTangentType)
                        continue

                    inTangentType = tangentType[0].replace("fixed",
                                                           "auto").replace(
                                                               "step", "auto")
                    outTangentType = tangentType[0].replace("fixed", "auto")

                    cmds.setKeyframe(loopObjAttr,
                                     time=time,
                                     insert=insert,
                                     shape=False,
                                     inTangentType=inTangentType,
                                     outTangentType=outTangentType)

            else:
                #allChannels   = animMod.getAllChannels(objects)
                #objAttrs      = ["%s.%s"%(objects[n], loopAttr) for n, loopObj in enumerate(allChannels) for loopAttr in loopObj]
                prevKeys = [
                    cmds.findKeyframe(obj, time=(time, time), which="previous")
                    for obj in objects
                ]
                tangentTypes = [
                    cmds.keyTangent(obj,
                                    query=True,
                                    outTangentType=True,
                                    time=(prevKeys[n], prevKeys[n]))
                    for n, obj in enumerate(objects)
                ]
                #prevKeys      = [cmds.findKeyframe(obj, time=(time,time), which="previous") for obj in objAttrs]
                #tangentTypes  = [cmds.keyTangent(obj, query=True, outTangentType=True, time=(prevKeys[n],prevKeys[n])) for n, obj in enumerate(objAttrs)]
                #key all atributes
                cmds.setKeyframe(objects,
                                 time=time,
                                 insert=insert,
                                 shape=False)
                #cmds.setKeyframe(objAttrs, time=time, insert=insert, shape=False)

                if insert:  #will force create key if there is no key
                    for n, loopTangent in enumerate(tangentTypes):
                        if not loopTangent:
                            cmds.setKeyframe(objects[n],
                                             time=time,
                                             insert=False,
                                             shape=False)
예제 #19
0
파일: align.py 프로젝트: Italic-/maya-prefs
    def align(self, sourceObjs, targetObj, frames=None, translate=True, rotate=True, showProgress=False, selectSorceObjs=False):
        
        if not sourceObjs or not targetObj: return    
        
        cmds.refresh(suspend=True)
        
        currFrame   = cmds.currentTime(query=True) 
        constraints = []
        setValues   = []
        modes       = [] 
        status      = "aTools - Aligning nodes..."
        
        if translate:   modes.append({"mode":"translate", "constrain":"pointConstraint"})
        if rotate:      modes.append({"mode":"rotate",    "constrain":"orientConstraint"})
        
        if showProgress: utilMod.startProgressBar(status)
        
        if not frames: 
            getCurves   = animMod.getAnimCurves()
            animCurves  = getCurves[0]
            getFrom     = getCurves[1]
            
            
            if animCurves:
                keysSel = animMod.getTarget("keysSel", animCurves, getFrom)
                frames  = utilMod.mergeLists(keysSel)
    
                if frames == []:
                     frames = [currFrame]   
            else:
                frames = [currFrame]
    
        if showProgress:
            totalSteps      = len(sourceObjs + frames)           
            firstStep       = 0
            thisStep        = 0
            estimatedTime   = None
            startChrono     = None            
        
        
        #get values
        for thisStep, loopSourceObj in enumerate(sourceObjs):
            
            if showProgress: startChrono = utilMod.chronoStart(startChrono, firstStep, thisStep, totalSteps, estimatedTime, status)   
                
            setValues.append({"modes":[], "values":[], "skips":[]})
            
            for loopMode in modes:
                                
                mode            = loopMode["mode"]
                constrainType   = loopMode["constrain"]
            
                allAttrs    = cmds.listAttr(loopSourceObj, settable=True, keyable=True)
                skip        = [loopXyz for loopXyz in ["x", "y", "z"] if "%s%s"%(mode, loopXyz.upper()) not in allAttrs]
                contrainFn  = eval("cmds.%s"%constrainType)
                
                with G.aToolsBar.createAToolsNode: constraints.append(contrainFn(targetObj, loopSourceObj, skip=skip)[0])
                                                
                setValues[-1]["modes"].append(mode)
                setValues[-1]["values"].append([cmds.getAttr("%s.%s"%(loopSourceObj, mode), time=loopKey)[0] for loopKey in frames])
                setValues[-1]["skips"].append(skip)
                
                
            if showProgress: estimatedTime = utilMod.chronoEnd(startChrono, firstStep, thisStep, totalSteps)
        
        #del constraints
        for loopConstrain in constraints: cmds.delete(loopConstrain) 
        
        for n, loopKey in enumerate(frames):
         
            if showProgress: 
                thisStep = thisStep + n + 1
                startChrono = utilMod.chronoStart(startChrono, firstStep, thisStep, totalSteps, estimatedTime, status)
                
            for nn, loopSourceObj in enumerate(sourceObjs):
                loopSetValue = setValues[nn]
                values       = loopSetValue["values"] 
                skips        = loopSetValue["skips"]
                
                for nnn, loopMode in enumerate(modes):
                    mode    = loopMode["mode"]
                    xyz     = [loopXyz for loopXyz in ["x", "y", "z"] if loopXyz not in skips[nnn]]
 
                    
                    for nnnn, loopXyz in enumerate(xyz):
                        attr    = "%s%s"%(mode, loopXyz.upper())
                        value   = values[nnn][n][nnnn]
                        
                        if len(frames) > 1: 
                            cmds.setKeyframe(loopSourceObj, attribute=attr, time=(loopKey,loopKey), value=value)
                 
                        if currFrame == loopKey:    cmds.setAttr("%s.%s"%(loopSourceObj, attr), value)
                        
                #euler filter        
                if n == len(frames)-1 and rotate:
                    animCurves  = utilMod.mergeLists([cmds.keyframe(loopSourceObj, query=True, name=True) for loopSourceObj in sourceObjs])
                    animMod.eulerFilterCurve(animCurves) 

            if showProgress: estimatedTime = utilMod.chronoEnd(startChrono, firstStep, thisStep, totalSteps)

        if showProgress: utilMod.setProgressBar(endProgress=True)
        if selectSorceObjs: cmds.select(sourceObjs)
        cmds.refresh(suspend=False)
예제 #20
0
    def applyMirror(self, pasteAndCycle=False):

        cmds.waitCursor(state=True)

        range = animMod.getTimelineRange()
        range[1] = int(range[1])
        total = range[1] - range[0]

        getCurves = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom = getCurves[1]

        invertRules = self.getInvertRules()

        if animCurves:
            status = "aTools - Applying mirror..."
            utilMod.startProgressBar(status)
            totalSteps = len(animCurves)
            firstStep = 0
            thisStep = 0
            estimatedTime = None
            startChrono = None

            mirrorCurves = animMod.getMirrorObjs(animCurves)
            keyValues = animMod.getTarget("keyValues", animCurves, getFrom)
            keyTimes = animMod.getTarget("keyTimes", animCurves, getFrom)
            currValues = animMod.getTarget("currValues", animCurves, getFrom)
            keysIndexSel = animMod.getTarget("keysIndexSel", animCurves,
                                             getFrom)
            keyTangentsAngle = animMod.getTarget("keyTangentsAngle",
                                                 animCurves, getFrom)
            keyTangentsType = animMod.getTarget("keyTangentsType", animCurves,
                                                getFrom)
            currTime = cmds.currentTime(query=True)

            if keysIndexSel:

                #create dummy key
                #objects     = animMod.getObjsSel()
                #mirrorObjs  = animMod.getMirrorObjs(objects)
                #animMod.createDummyKey(mirrorObjs)

                for thisStep, aCurve in enumerate(animCurves):

                    startChrono = utilMod.chronoStart(startChrono, firstStep,
                                                      thisStep, totalSteps,
                                                      estimatedTime, status)

                    mCurve = mirrorCurves[thisStep]
                    isCenterCurve = (mCurve == None)
                    mirrorInvertValue = self.mirrorInvert(
                        aCurve, isCenterCurve, invertRules)
                    if mCurve and cmds.objExists(mCurve):
                        tCurve = mCurve
                    else:
                        tCurve = aCurve

                    if not cmds.objExists(tCurve): continue

                    animMod.createDummyKey([tCurve])

                    if len(keysIndexSel[thisStep]) > 0:
                        #delete keys
                        cmds.cutKey(
                            tCurve,
                            time=(
                                keyTimes[thisStep][keysIndexSel[thisStep][0]],
                                keyTimes[thisStep][keysIndexSel[thisStep][-1]]
                            ),
                            clear=True)

                        for key in keysIndexSel[thisStep]:
                            keyValue = keyValues[thisStep][
                                key] * mirrorInvertValue
                            inTangAngleValue = keyTangentsAngle[thisStep][key][
                                0] * mirrorInvertValue
                            outTangAngleValue = keyTangentsAngle[thisStep][
                                key][1] * mirrorInvertValue

                            #apply keys
                            if pasteAndCycle:
                                t = keyTimes[thisStep][key] + (total / 2.)

                                if t == range[1]:
                                    #repeat key at first frame
                                    t1 = t - total
                                    time = (t1, t1)
                                    cmds.setKeyframe(tCurve,
                                                     time=time,
                                                     value=keyValue)
                                    cmds.keyTangent(tCurve,
                                                    time=time,
                                                    inAngle=inTangAngleValue,
                                                    outAngle=outTangAngleValue)
                                    cmds.keyTangent(
                                        tCurve,
                                        time=time,
                                        inTangentType=keyTangentsType[thisStep]
                                        [key][0],
                                        outTangentType=keyTangentsType[
                                            thisStep][key][1])

                                elif t > range[1]:
                                    #fist half
                                    t -= total

                                time = (t, t)

                            else:
                                time = (keyTimes[thisStep][key],
                                        keyTimes[thisStep][key])

                            cmds.setKeyframe(tCurve, time=time, value=keyValue)
                            cmds.keyTangent(tCurve,
                                            time=time,
                                            inAngle=inTangAngleValue,
                                            outAngle=outTangAngleValue)
                            cmds.keyTangent(
                                tCurve,
                                time=time,
                                inTangentType=keyTangentsType[thisStep][key]
                                [0],
                                outTangentType=keyTangentsType[thisStep][key]
                                [1])
                    else:  #no keys#invert translate x
                        keyValue = currValues[thisStep] * mirrorInvertValue

                        #apply keys
                        cmds.setKeyframe(tCurve,
                                         time=(currTime, currTime),
                                         value=keyValue)

                    animMod.deleteDummyKey([tCurve])

                    estimatedTime = utilMod.chronoEnd(startChrono, firstStep,
                                                      thisStep, totalSteps)

                #delete dummy key
                #animMod.deleteDummyKey(mirrorObjs)

            self.selectMirrorObjs(False)
            utilMod.setProgressBar(endProgress=True)

        animMod.refresh()
        cmds.waitCursor(state=False)
예제 #21
0
 def create(self, *args):
     
     
     img = cmds.iconTextButton("TempCustomPivotBtn", query=True, image=True)
     onOff = (img[-10:-4] == "active")
     if onOff: 
         self.clear()
         cmds.select(self.sel)
         return
     
     cmds.undoInfo(openChunk=True)
     cmds.undoInfo(closeChunk=True)
     cmds.undoInfo(openChunk=True)
     cmds.undoInfo(closeChunk=True)
     cmds.undoInfo(openChunk=True)
     cmds.undoInfo(closeChunk=True)
     cmds.undoInfo(openChunk=True)
     
     self.clear()       
     
     
     getCurves  = animMod.getAnimCurves()
     animCurves = getCurves[0]
     getFrom    = getCurves[1] 
     
     if animCurves:        
         keyTimes            = animMod.getTarget("keyTimes", animCurves, getFrom)
           
     self.sel = cmds.ls(selection=True)
     if not self.sel: return
             
     cmds.iconTextButton("TempCustomPivotBtn", edit=True, image= uiMod.getImagePath("specialTools_create_temp_custom_pivot_active"),         highlightImage= uiMod.getImagePath("specialTools_create_temp_custom_pivot_active"))
    
     targetObj  = self.sel[-1]  
     aToolsMod.saveInfoWithScene(self.STORE_NODE, self.CTRLS, self.sel)
     
     currentFrame = cmds.currentTime(query=True) 
     aToolsMod.saveInfoWithScene(self.STORE_NODE, self.CURRENTFRAME, currentFrame)
     
     locators = []
     for loopSel in self.sel: 
         nameSpace       = utilMod.getNameSpace([loopSel])
         loopSelName     = "%s_%s"%(nameSpace[0][0], nameSpace[1][0])  
         locatorName     = "tempCustomPivot_%s"%loopSelName
         
         locator = animMod.createNull(locatorName)
         locators.append(locator)
     
         G.aToolsBar.align.align([locator], loopSel)
     
         
     locatorGroup = "tempCustomPivot_group"
     animMod.group(name=locatorGroup)        
     G.aToolsBar.align.align([locatorGroup], targetObj)
     with G.aToolsBar.createAToolsNode: cmds.parent(locators, locatorGroup)
     cmds.select(locatorGroup, replace=True)
     
     locators.append(locatorGroup)   
     
     aToolsMod.saveInfoWithScene(self.STORE_NODE, self.LOCATORS, locators)
  
     #parent ctrls to locator
     constraints = ["%s_tempCustomPivot_constraint"%loopConstraint for loopConstraint in self.sel]
     
     aToolsMod.saveInfoWithScene(self.STORE_NODE, self.CONSTRAINTS, constraints)
     
     for n, loopSel in enumerate(self.sel):
         with G.aToolsBar.createAToolsNode: cmds.parentConstraint(locators[n], loopSel, name=constraints[n], maintainOffset=True)
         constraintNode = "%s.blendParent1"%loopSel
         if not cmds.objExists(constraintNode): continue
         cmds.setKeyframe(constraintNode)
         if keyTimes:
             for loopTime in keyTimes[0]:
                 cmds.setKeyframe("%s.tx"%locatorGroup, time=(loopTime,loopTime))
                 if loopTime != currentFrame:
                     cmds.setKeyframe(constraintNode, time=(loopTime,loopTime), value=0)
     
     #enter edit mode
     cmds.setToolTo(cmds.currentCtx())
     cmds.ctxEditMode()
     
     #scriptjob    
     cmds.scriptJob(runOnce = True, killWithScene = True,  event =('SelectionChanged',  self.scriptJob_SelectionChanged))
예제 #22
0
def smartSnapKeys():
        
    getCurves       = animMod.getAnimCurves()
    animCurves      = getCurves[0]
    
    if not animCurves or len(animCurves) == 0: return
    
    getFrom         = getCurves[1]           
    keyTimes        = animMod.getTarget("keyTimes", animCurves, getFrom)  
    keysSel         = animMod.getTarget("keysSel", animCurves, getFrom)
    hasDecimalKeys  = False
        
    for loopKey in utilMod.mergeLists(keysSel):
        if loopKey != round(loopKey) > 0:
            hasDecimalKeys = True
            break
    
    if not hasDecimalKeys: return
      
    keyTangentsType = animMod.getTarget("keyTangentsType", animCurves, getFrom)
    firstStep       = 0
    totalSteps      = len(animCurves)
    estimatedTime   = None
    status          = "aTools - Smart Snap Curves..."
    startChrono     = None
    utilMod.startProgressBar(status)
    
    for thisStep, loopCurve in enumerate(animCurves):
        
        startChrono = utilMod.chronoStart(startChrono, firstStep, thisStep, totalSteps, estimatedTime, status)
        
        if None in [keyTimes[thisStep], keysSel[thisStep]]: continue
        
        stepKeys        = [loopKey for nn, loopKey in enumerate(keyTimes[thisStep]) if loopKey != round(loopKey) and loopKey in keysSel[thisStep] and keyTangentsType[thisStep][nn][1] == "step"]
        linearKeys      = [loopKey for nn, loopKey in enumerate(keyTimes[thisStep]) if loopKey != round(loopKey) and loopKey in keysSel[thisStep] and keyTangentsType[thisStep][nn][1] == "linear"]
        decimalKeys     = [loopKey for nn, loopKey in enumerate(keyTimes[thisStep]) if loopKey != round(loopKey) and loopKey in keysSel[thisStep] and loopKey not in stepKeys + linearKeys]
        
        for loopKey in stepKeys:        cmds.snapKey(loopCurve, time=(loopKey, loopKey))
        for loopKey in linearKeys:      cmds.snapKey(loopCurve, time=(loopKey, loopKey))
        
        if len(decimalKeys) == 0: continue
        
        if not getFrom: 
            if cmds.keyframe(query=True, selected=True) != None: getFrom = "graphEditor"
        
        #inLinearKeys    = [round(loopKey) for nn, loopKey in enumerate(keyTimes[thisStep]) if keyTangentsType[thisStep][nn][0] == "linear"]
        #outLinearKeys   = [round(loopKey) for nn, loopKey in enumerate(keyTimes[thisStep]) if keyTangentsType[thisStep][nn][1] == "linear"]
        createKeys      = list(set([round(loopKey) for loopKey in decimalKeys]))
        selectKeys      = []
        
        #print "inlinearKeys", inLinearKeys, outLinearKeys  
        
        
        if getFrom == "graphEditor": 
            selectKeys  = list(set([round(loopKey) for loopKey in keysSel[thisStep] if round(loopKey) in createKeys]))
         
        for loopKey in createKeys:      cmds.setKeyframe(loopCurve, time=(loopKey, loopKey), insert=True)            
        for loopKey in selectKeys:      cmds.selectKey(loopCurve, addTo=True, time=(loopKey, loopKey))    
        for loopKey in decimalKeys:     cmds.cutKey(loopCurve, time=(loopKey, loopKey))        
        #for loopKey in outLinearKeys:   cmds.keyTangent(loopCurve, edit=True, time=(loopKey, loopKey), outTangentType="linear")
        #for loopKey in inLinearKeys:    cmds.keyTangent(loopCurve, edit=True, time=(loopKey, loopKey), inTangentType="linear")
        
        estimatedTime = utilMod.chronoEnd(startChrono, firstStep, thisStep, totalSteps)
    
    utilMod.setProgressBar(endProgress=True)
예제 #23
0
 def applyMirror(self, pasteAndCycle=False):
 
     cmds.waitCursor(state=True) 
     
     range       = animMod.getTimelineRange()
     range[1]    = int(range[1])
     total       = range[1]-range[0]
     
     getCurves   = animMod.getAnimCurves()
     animCurves  = getCurves[0]
     getFrom     = getCurves[1] 
     
     invertRules = self.getInvertRules()
     
     if animCurves:
         status          = "aTools - Applying mirror..."
         utilMod.startProgressBar(status)
         totalSteps      = len(animCurves)           
         firstStep       = 0
         thisStep        = 0
         estimatedTime   = None
         startChrono     = None
         
         mirrorCurves        = animMod.getMirrorObjs(animCurves)
         keyValues           = animMod.getTarget("keyValues", animCurves, getFrom)
         keyTimes            = animMod.getTarget("keyTimes", animCurves, getFrom)
         currValues          = animMod.getTarget("currValues", animCurves, getFrom)
         keysIndexSel        = animMod.getTarget("keysIndexSel", animCurves, getFrom)
         keyTangentsAngle    = animMod.getTarget("keyTangentsAngle", animCurves, getFrom)
         keyTangentsType     = animMod.getTarget("keyTangentsType", animCurves, getFrom)
         currTime            = cmds.currentTime(query=True)
         
         
         
         if keysIndexSel:
             
             #create dummy key
             #objects     = animMod.getObjsSel()
             #mirrorObjs  = animMod.getMirrorObjs(objects)
             #animMod.createDummyKey(mirrorObjs)
                             
             for thisStep, aCurve in enumerate(animCurves):
                 
                 startChrono     = utilMod.chronoStart(startChrono, firstStep, thisStep, totalSteps, estimatedTime, status)
                 
                 mCurve              = mirrorCurves[thisStep]
                 isCenterCurve       = (mCurve == None)                
                 mirrorInvertValue   = self.mirrorInvert(aCurve, isCenterCurve, invertRules)
                 if mCurve and cmds.objExists(mCurve):
                     tCurve = mCurve
                 else:
                     tCurve = aCurve
                     
                 if not cmds.objExists(tCurve): continue
                        
                 
                 animMod.createDummyKey([tCurve])
                 
                 if len(keysIndexSel[thisStep]) > 0:
                     #delete keys
                     cmds.cutKey(tCurve, time=(keyTimes[thisStep][keysIndexSel[thisStep][0]],keyTimes[thisStep][keysIndexSel[thisStep][-1]]), clear=True) 
                 
                     for key in keysIndexSel[thisStep]:
                         keyValue            = keyValues[thisStep][key] * mirrorInvertValue
                         inTangAngleValue    = keyTangentsAngle[thisStep][key][0] * mirrorInvertValue
                         outTangAngleValue   = keyTangentsAngle[thisStep][key][1] * mirrorInvertValue
                            
                         
                         #apply keys
                         if pasteAndCycle:
                             t = keyTimes[thisStep][key] + (total/2.)
                             
                             if t == range[1]:
                                 #repeat key at first frame
                                 t1 = t-total
                                 time = (t1,t1)
                                 cmds.setKeyframe(tCurve, time=time, value=keyValue)
                                 cmds.keyTangent(tCurve,  time=time, inAngle=inTangAngleValue, outAngle=outTangAngleValue)
                                 cmds.keyTangent(tCurve,  time=time, inTangentType=keyTangentsType[thisStep][key][0], outTangentType=keyTangentsType[thisStep][key][1])
                                            
                             elif t > range[1]:
                                 #fist half
                                 t -= total
                             
                             time        = (t,t)
                             
                             
                             
                         else:
                             time        = (keyTimes[thisStep][key],keyTimes[thisStep][key])
                             
                         
                             
                         cmds.setKeyframe(tCurve, time=time, value=keyValue)
                         cmds.keyTangent(tCurve,  time=time, inAngle=inTangAngleValue, outAngle=outTangAngleValue)
                         cmds.keyTangent(tCurve,  time=time, inTangentType=keyTangentsType[thisStep][key][0], outTangentType=keyTangentsType[thisStep][key][1])
                 else: #no keys#invert translate x
                     keyValue = currValues[thisStep] * mirrorInvertValue
                        
                     
                     #apply keys
                     cmds.setKeyframe(tCurve, time=(currTime,currTime), value=keyValue)
                     
                 animMod.deleteDummyKey([tCurve]) 
                 
                 estimatedTime = utilMod.chronoEnd(startChrono, firstStep, thisStep, totalSteps)        
                 
                     
             #delete dummy key
             #animMod.deleteDummyKey(mirrorObjs)
         
         self.selectMirrorObjs(False)
         utilMod.setProgressBar(endProgress=True)
                        
     animMod.refresh()
     cmds.waitCursor(state=False) 
예제 #24
0
    def setTween(self, percent, *args):

        #utilMod.timer("s")


        G.TM_lastTweenCommand = "self.setTween(%s)"%percent

        getCurves   = animMod.getAnimCurves()
        animCurves  = getCurves[0]
        getFrom     = getCurves[1]

        if animCurves:
            status          = "aTools - Tween Machine..."
            utilMod.startProgressBar(status)
            totalSteps      = len(animCurves)
            firstStep       = 0
            thisStep        = 0
            estimatedTime   = None
            startChrono     = None

            cmds.waitCursor(state=True)
            cmds.refresh(suspend=True)


            keysSel         = animMod.getTarget("keysSel", animCurves, getFrom)
            keyTimes        = animMod.getTarget("keyTimes", animCurves)
            timelineTime    = None
            #keysSelMerged   = utilMod.mergeLists(keysSel)



            # reverse order to get ease in and out smoothly
            if 0 < percent <= 50 or percent == 100:
                for loopVal in keysSel:
                    loopVal.reverse()

            #utilMod.timer()

            """
            if len(keysSelMerged) == 0:
                if not timelineTime: timelineTime = [animMod.getTimelineTime()]
                cmds.setKeyframe(animCurves, time=timelineTime[0])
            elif len(keysSelMerged) == 1:
                cmds.setKeyframe(animCurves, time=keysSelMerged[0])
            """


            for thisStep, loopCurve in enumerate(animCurves):

                if cmds.progressBar(G.progBar, query=True, isCancelled=True ):
                    utilMod.setProgressBar(endProgress=True)
                    break

                startChrono     = utilMod.chronoStart(startChrono, firstStep, thisStep, totalSteps, estimatedTime, status)

                if not keysSel[thisStep]:
                    if not timelineTime: timelineTime = [animMod.getTimelineTime()]
                    time = timelineTime
                else:
                    time = [(loopTime,loopTime) for loopTime in keysSel[thisStep]]
                    # if all keys selected, use timeline time instead
                    if len(time) == len(keyTimes[thisStep]):
                        if not timelineTime: timelineTime = [animMod.getTimelineTime()]
                        time = timelineTime



                for loopTime in time:


                    prevKeyTime    = cmds.findKeyframe(loopCurve, time=loopTime, which="previous")
                    nextKeyTime    = cmds.findKeyframe(loopCurve, time=loopTime, which="next")

                    if prevKeyTime == nextKeyTime and prevKeyTime != loopTime[0] and percent != "linear_next" and percent != "linear_prev": # if there is no previous or next key and at least one key
                        cmds.setKeyframe(loopCurve, time=loopTime)

                    elif prevKeyTime != time[0]:

                        if percent == "linear_prev":

                            prevKeyTime     = nextKeyTime
                            nextKeyTime     = cmds.findKeyframe(loopCurve, time=(prevKeyTime,prevKeyTime), which="next")
                            prevKeyVal      = cmds.keyframe(loopCurve, query=True, time=(prevKeyTime, prevKeyTime), valueChange=True)[0]
                            nextKeyVal      = cmds.keyframe(loopCurve, query=True, time=(nextKeyTime, nextKeyTime), valueChange=True)[0]

                            if nextKeyTime == prevKeyTime:
                                value       = prevKeyVal
                            else:
                                value       = prevKeyVal + ((nextKeyVal - prevKeyVal)/(nextKeyTime - prevKeyTime)*(loopTime[0] - prevKeyTime))

                        elif percent == "linear_next":

                            nextKeyTime     = prevKeyTime
                            prevKeyTime     = cmds.findKeyframe(loopCurve, time=(nextKeyTime,nextKeyTime), which="previous")
                            prevKeyVal      = cmds.keyframe(loopCurve, query=True, time=(prevKeyTime, prevKeyTime), valueChange=True)[0]
                            nextKeyVal      = cmds.keyframe(loopCurve, query=True, time=(nextKeyTime, nextKeyTime), valueChange=True)[0]

                            if nextKeyTime == prevKeyTime:
                                value       = prevKeyVal
                            else:
                                value       = prevKeyVal + ((nextKeyVal - prevKeyVal)/(nextKeyTime - prevKeyTime)*(loopTime[0] - prevKeyTime))

                        else:

                            animMod.eulerFilterCurve([loopCurve])

                            prevKeyVal = cmds.keyframe(loopCurve, query=True, time=(prevKeyTime, prevKeyTime), valueChange=True)[0]
                            nextKeyVal = cmds.keyframe(loopCurve, query=True, time=(nextKeyTime, nextKeyTime), valueChange=True)[0]

                            #print "prevKeyVal", prevKeyVal, nextKeyVal

                            #if prevKeyVal == nextKeyVal:
                                #if not time[0] in keysSel[thisStep]: cmds.setKeyframe(loopCurve, time=loopTime)
                                #continue


                            if percent == "linear": value  = prevKeyVal + ((nextKeyVal - prevKeyVal)/(nextKeyTime - prevKeyTime)*(loopTime[0] - prevKeyTime))
                            else:                   value  = ((nextKeyVal-prevKeyVal)/100.*percent)+prevKeyVal


                        tangentType     = cmds.keyTangent(loopCurve, query=True, outTangentType=True, time=(prevKeyTime,prevKeyTime))[0]
                        inTangentType   = tangentType.replace("fixed", "auto").replace("step", "auto")
                        outTangentType  = tangentType.replace("fixed", "auto")

                        if not time[0] in keysSel[thisStep]: cmds.setKeyframe(loopCurve, time=loopTime)

                        cmds.keyframe(loopCurve, edit=True, time=loopTime, valueChange=value)
                        cmds.keyTangent(loopCurve, edit=True, time=loopTime, inTangentType=inTangentType, outTangentType=outTangentType)
                        #keycolor
                        if 1 <= percent <= 99 or percent == "linear": cmds.keyframe(loopCurve ,edit=True,time=loopTime, tickDrawSpecial=self.getColoredKeys())



                    if getFrom == "graphEditor":
                        #curvesToSelect.append([loopCurve, loopTime])
                        cmds.selectKey(loopCurve, addTo=True, time=loopTime)


                estimatedTime = utilMod.chronoEnd(startChrono, firstStep, thisStep, totalSteps)

            #utilMod.timer()
            """
            #APPLY
            if len(curvesToKey) > 0: cmds.setKeyframe(curvesToKey)

            for loopVar in curvesToValue:
                cmds.keyframe(loopVar[0], edit=True, time=loopVar[1], valueChange=loopVar[2])
                cmds.keyTangent(loopVar[0], edit=True, time=loopVar[1], inTangentType=loopVar[3], outTangentType=loopVar[4])

            for loopVar in curvesToColor:  cmds.keyframe(loopVar[0], edit=True, time=loopVar[1], tickDrawSpecial=self.getColoredKeys())
            for loopVar in curvesToSelect: cmds.selectKey(loopVar[0], addTo=True, time=loopVar[1])
            """


            cmds.refresh(suspend=False)
            cmds.waitCursor(state=False)
            utilMod.setProgressBar(endProgress=True)
예제 #25
0
def eulerFilterSelection():
    getCurves   = animMod.getAnimCurves()
    animCurves  = getCurves[0]
    
    animMod.eulerFilterCurve(animCurves) 
예제 #26
0
    def setTangent(self, tangentType, tangentInOut="inOut", targetKeys="selected", *args):

        # utilMod.timer(mode="s", function="MAIN FUNCTION")

        cmds.waitCursor(state=True)

        """
        cmds.undoInfo(openChunk=True)
        cmds.undoInfo(closeChunk=True)
        cmds.undoInfo(openChunk=True)
        cmds.undoInfo(closeChunk=True)
        cmds.undoInfo(openChunk=True)
        cmds.undoInfo(closeChunk=True)
        cmds.undoInfo(openChunk=True)
        """

        # tangentType = flow, bounce, auto, etc
        # targetKeys = all, selected
        # tangentInOut = inOut, in, out

        # set default tangent type
        if tangentType == "flow":
            cmds.keyTangent(edit=True, g=True, inTangentType="auto", outTangentType="auto")
        elif tangentType == "step":
            cmds.keyTangent(edit=True, g=True, outTangentType=tangentType)
        elif tangentType != "bounce":
            cmds.keyTangent(edit=True, g=True, inTangentType=tangentType, outTangentType=tangentType)

        # get target curves
        getCurves = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom = getCurves[1]

        # if there is no curves, exit
        if animCurves:
            status = "aTools - Tangents..."
            utilMod.startProgressBar(status)
            totalSteps = len(animCurves)
            firstStep = 0
            thisStep = 0
            estimatedTime = None
            startChrono = None

            index = None
            time = None

            if targetKeys == "all":  # apply for all keys
                time = (-50000, 500000)

                if not self.isDefaultTangent(tangentType):
                    index = animMod.getTarget("keyIndexTimes", animCurves, getFrom)

                self.applyTangent(animCurves, tangentType, getFrom, time, index)

            elif targetKeys == "selected":  # apply on a range
                if getFrom == "timeline":
                    time = animMod.getTimelineRange()
                    time = (time[0], time[1])  # flow and bounce
                    if not self.isDefaultTangent(tangentType):
                        index = animMod.getTarget("keysIndexSel", animCurves, getFrom)
                    self.applyTangent(animCurves, tangentType, getFrom, time, index, tangentInOut)

                else:
                    if self.isDefaultTangent(tangentType):  # if the tangent types are default maya types
                        # apply individually on each key
                        keysSel = animMod.getTarget("keysSel", animCurves, getFrom)

                        for thisStep, aCurve in enumerate(animCurves):
                            if cmds.progressBar(G.progBar, query=True, isCancelled=True):
                                utilMod.setProgressBar(endProgress=True)
                                break
                            startChrono = utilMod.chronoStart(
                                startChrono, firstStep, thisStep, totalSteps, estimatedTime, status
                            )

                            for loopKey in keysSel[thisStep]:
                                time = (loopKey, loopKey)
                                self.applyTangent(aCurve, tangentType, getFrom, time, index, tangentInOut)

                            estimatedTime = utilMod.chronoEnd(startChrono, firstStep, thisStep, totalSteps)

                    else:  # flow and bounce
                        index = animMod.getTarget("keysIndexSel", animCurves, getFrom)
                        self.applyTangent(animCurves, tangentType, getFrom, time, index, tangentInOut)
            else:  # first and last frame
                keyTimes = animMod.getTarget("keyTimes", animCurves, getFrom)
                keyIndexTimes = animMod.getTarget("keyIndexTimes", animCurves, getFrom)

                self.bounceEnds(animCurves, tangentType, getFrom, tangentInOut, keyTimes, keyIndexTimes, targetKeys)

            utilMod.setProgressBar(endProgress=True)
        # cmds.undoInfo(closeChunk=True)

        cmds.waitCursor(state=False)