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)
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)
def eulerFilterSelection(): getCurves = animMod.getAnimCurves() animCurves = getCurves[0] animMod.eulerFilterCurve(animCurves)
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)
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)
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)