本文整理汇总了Python中maya.cmds.keyframe函数的典型用法代码示例。如果您正苦于以下问题:Python keyframe函数的具体用法?Python keyframe怎么用?Python keyframe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了keyframe函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keyCopyObjectOnce
def keyCopyObjectOnce( target, start, end ):
otherTarget = ''
if target in CtlInfo.leftCtls:
otherTarget = target.replace( '_L1_', '_R1_' )
elif target in CtlInfo.rightCtls:
otherTarget = target.replace( '_R1_', '_L1_' )
if not otherTarget: return None
attrs = cmds.listAttr( target, k=1 )
for attr in attrs:
times = cmds.keyframe( target+'.'+attr, q=1, t=(start,end), tc=1 )
if not times: continue
values = cmds.keyframe( target+'.'+attr, q=1, t=(start,end), vc=1 )
keyLocks = cmds.keyTangent( target+'.'+attr, q=1, t=(start,end), lock=1 )
inAngles = cmds.keyTangent( target+'.'+attr, q=1, t=(start,end), ia=1 )
outAngles = cmds.keyTangent( target+'.'+attr, q=1, t=(start,end), oa=1 )
cmds.cutKey( otherTarget+'.'+attr, t=(start+0.01, end-0.01) )
for i in range( len( times ) ):
value = values[i]
ia = inAngles[i]
oa = outAngles[i]
cmds.setKeyframe( otherTarget+'.'+attr, t=times[i], v=value )
cmds.keyTangent( otherTarget+'.'+attr, e=1, t=(times[i],times[i]), lock=0 )
cmds.keyTangent( otherTarget+'.'+attr, e=1, t=(times[i],times[i]), ia=ia )
cmds.keyTangent( otherTarget+'.'+attr, e=1, t=(times[i],times[i]), oa=oa )
cmds.keyTangent( otherTarget+'.'+attr, e=1, t=(times[i],times[i]), lock=keyLocks[i] )
示例2: random
def random():
import random
curves = mc.keyframe(q=1, sl=1, name=1)
for curve in curves:
indexes = mc.keyframe(curve, q=1, sl=1, iv=1)
for index in indexes:
mc.keyframe(curve, r=1, vc=random.uniform(-1.0, 1.0), index=tuple([index]) )
示例3: camMovementDetector
def camMovementDetector():
shotCam = [cam for cam in cmds.listCameras(perspective = True) if cam != 'persp' if cmds.objExists('%s.type' % cam) if cmds.getAttr('%s.type' % cam) == 'shotCam']
shotCam = shotCam[0] if shotCam else None
animated_curves = []
anim_curves = cmds.findKeyframe(shotCam, curve = True)
if anim_curves:
keyframes_min_max = []
for crv in anim_curves:
keys = cmds.keyframe(crv, valueChange = True, q = True)
frames = cmds.keyframe(crv, timeChange = True, q = True)
keyframes = dict( zip(keys, frames) )
if keyframes:
if len(keyframes) > 1:
start_anim = max( keyframes.values() )
stop_anim = min( keyframes.values() )
keyframes_min_max.append(start_anim) if start_anim not in keyframes_min_max else None
keyframes_min_max.append(stop_anim) if stop_anim not in keyframes_min_max else None
if keyframes_min_max:
return min(keyframes_min_max), max(keyframes_min_max)
示例4: hold
def hold():
curves = mc.keyframe(q=1, sl=1, name=1)
for curve in curves:
index = mc.keyframe(curve, q=1, sl=1, iv=1)
firstValue = mc.keyframe(curve, q=1, sl=1, vc=1)[0]
mc.keyframe(curve, vc=firstValue, index=(index[0], index[-1]))
mc.keyTangent(itt='flat', ott='flat')
示例5: fillGapLinear
def fillGapLinear(item=None,step=None, start=None, end=None) :
try :
if item is None : item = getItem()
if step is None : step = datarate.get(item)
if start is None or end is None :
(start, end) = findCurrentGap(item)
except ValueError as e :
print "Could not fill linear gap: " + str(e)
return
fillObj = item
gapval = [
m.keyframe(fillObj + ".tx", q=True, time=( start, end ), vc=True),
m.keyframe(fillObj + ".ty", q=True, time=( start, end ), vc=True),
m.keyframe(fillObj + ".tz", q=True, time=( start, end ), vc=True) ]
chan = [ ".tx", ".ty", ".tz" ]
ktime = 0
for i in range(0,3) :
ktime = start + step
while ktime <= end - step :
progress = (ktime-start) / (end - start)
kvalue = (gapval[i][-1] - gapval[i][0]) * progress + gapval[i][0]
m.setKeyframe( fillObj + chan[i], t=ktime, value = kvalue)
ktime = ktime + step
setActiveKeys(fillObj)
示例6: chimaPullThemDown
def chimaPullThemDown() :
num = -6975.209
nodes = mc.ls( sl=True )
tys = []
for node in nodes :
src = mc.listConnections( '%s.ty' % node , p=True , s=True , d=False )[0]
srcType = mc.nodeType( src )
ty = ''
if srcType == 'character' :
ty = mc.listConnections( src , s=True , d=False )[0]
elif srcType == 'animCurveTL' :
ty = src.split( '.' )[0]
else :
print '%s has been constrained to object' % node
ty = None
if ty :
tys.append( ty )
mc.keyframe( tys ,
e=True ,
includeUpperBound=False ,
animation='objects' ,
time=(0,100000) ,
r=True ,
o='move' ,
timeChange=0 ,
valueChange=num
)
示例7: plot
def plot():
curves = mc.keyframe(q=1, sl=1, name=1)
if type(curves).__name__ != 'NoneType':
for curve in curves:
indexes = mc.keyframe(curve, q=1, sl=1, iv=1)
if len(indexes) != 1:
startTime = int(mc.keyframe(curve, q=1, tc=1, index=tuple([indexes[0]]))[0])
endTime = int(mc.keyframe(curve, q=1, tc=1, index=tuple([indexes[1]]))[0])
mc.selectKey(cl=1)
for point in range(startTime, endTime):
mc.setKeyframe(curve, insert=1, time=point)
mc.selectKey(curve, time=( (startTime+0.01), (endTime-0.01) ), add=1, k=1)
else:
mc.warning('Only one keyframe is selected for the curve ' + curve + '.')
else:
sels = mc.ls(sl=1)
if sels:
timeSlider = mm.eval('$tmp = $gPlayBackSlider')
if mc.timeControl(timeSlider, q=1, rv=1) == 1:
startTime = int(mc.timeControl(timeSlider, q=1, ra=1)[0])
endTime = int(mc.timeControl(timeSlider, q=1, ra=1)[1])
else:
startTime = int(mc.playbackOptions(q=1, min=1))
endTime = int(mc.playbackOptions(q=1, max=1))
curves = mc.keyframe(q=1, name=1)
for curve in curves:
for point in range(startTime, endTime):
mc.setKeyframe(curve, insert=1, time=point)
mc.selectKey(curve, time=( (startTime+0.01), (endTime-0.01) ), add=1, k=1)
else:
mc.warning('Nothing is selected.')
示例8: getKeyByObject
def getKeyByObject(obj):
data = dict()
#- object exists ?
if not mc.objExists(obj):
return data
data['object'] = re.search('\w+$', obj).group()
#- object has attributes ?
attributes = mc.listAttr(obj, k=True)
if not attributes:
return data
#- get keys
for attr in attributes:
times = mc.keyframe(obj, at=attr, q=True, tc=True)
values = mc.keyframe(obj, at=attr, q=True, vc=True)
inAngles = mc.keyTangent(obj, at=attr, q=True, ia=True)
outAngles = mc.keyTangent(obj, at=attr, q=True, oa=True)
inWeights = mc.keyTangent(obj, at=attr, q=True, iw=True)
outWeights = mc.keyTangent(obj, at=attr, q=True, ow=True)
#- keys not found..
if not times:
continue
#- save data..
data.setdefault('keyData', {})[attr] = zip(times, values, inAngles, inWeights, outAngles, outWeights)
return data
示例9: on_actionLoadSourceControl_triggered
def on_actionLoadSourceControl_triggered(self, clicked=None):
if clicked == None:return
selectOBJ = mc.ls(sl=True)
if len(selectOBJ) == 0:return
self.sourceControlFLD.setText(selectOBJ[0])
KeyableAttr = mc.listAttr(selectOBJ[0], k=True)
del self.sourceAtrLst[:]
del self.targentAtrLst[:]
# loop Attributes..
for Attr in KeyableAttr:
SDKeys = mc.connectionInfo('%s.%s'%(selectOBJ[0], Attr), dfs=True)
# loop driven Attributes..
for key in SDKeys:
if mc.nodeType(key) == 'unitConversion':
keyNode = mc.connectionInfo('%s.output'%key.split('.')[0], dfs=True)[0].split('.')[0]
elif mc.nodeType(key) not in ('animCurve','animCurveTA', 'animCurveTL', 'animCurveTT','animCurveTU','animCurveUA','animCurveUL','animCurveUT','animCurveUU'):
continue
else:
keyNode = key.split('.')[0]
DriverValues = mc.keyframe(keyNode, q=True, fc=True)
DrivenValues = mc.keyframe(keyNode, q=True, vc=True)
DriverAttribute = mc.connectionInfo('%s.output'%keyNode, dfs=True)[0]
# if more than one Drivers, from add node get the attribute..
if DriverAttribute.endswith(']'):
DriverAttribute = mc.connectionInfo('%s.output'%(DriverAttribute.split('.')[0]), dfs=True)[0]
self.sourceAtrLst.append(['%s.%s'%(selectOBJ[0], Attr), DriverAttribute, DriverValues, DrivenValues])
self.on_actionInputSearchReplace_triggered()
示例10: canInsertKey
def canInsertKey(attr):
'''
Returns True if a given attribute can be keyframed with the insert keyframe
command option.
Raises KeyframeQueryFailed
'''
# Insert keys match the curvature of the existing curve.
# They have a few limitations though...
try:
# You can't insert a keyframe if there are no keyframes to begin with
if cmd.keyframe(attr, query=1, keyframeCount=1) == 0:
return False
except RuntimeError as err:
raise KeyframeQueryFailed(err)
# You don't want to insert a keyframe if the user changed something.
# Keyframe always returns a list
oldValue = cmd.keyframe(attr, query=1, eval=1)
# GetAttr returns a single value if only one. Otherwise, a list of
# tuples ex: [(0, 0, 0)]
newValue = cmd.getAttr(attr)
if not isinstance(newValue, collections.Iterable) and len(oldValue) == 1:
# There's only one attribute.
if round(oldValue[0], 6) != round(newValue, 6):
return False
elif len(oldValue) == len(newValue[0]):
# Attribute is an array, check each one.
if any(round(oldValue[x], 6) != round(newValue[0][x], 6) for x in range(len(oldValue))):
return False
else:
# I don't know what this is.
return False
return True
示例11: __init__
def __init__( self, attrpath, keyTime=None, keyIdx=None ):
#if the attrpath doesn't exist, then just create an empty key instance
if not cmd.objExists(attrpath):
self.obj = None
self.attr = None
self.time = None
self.value = None
self.iw = None
self.ow = None
self.itt = None
self.ott = None
return
self.obj,self.attr = attrpath.split('.')
#make sure the attr name is the long version of the name, its too annoying to have to deal with shortnames AND long names...
self.attr = cmd.attributeQuery(self.attr,longName=True,node=self.obj)
#and just for uber convenience, store the attrpath as well...
self.attrpath = attrpath
if keyIdx != None:
times = cmd.keyframe(attrpath,index=keyIdx,query=True)
self.time = times[0]
elif keyTime != None:
self.time = keyTime
#is there a key at the time?
if cmd.keyframe(attrpath,time=(keyTime,),query=True,keyframeCount=True):
self.value = cmd.keyframe(attrpath,time=(keyTime,),query=True,valueChange=True)[0]
self.iw,self.ow,self.ia,self.oa = cmd.keyTangent(attrpath,time=(keyTime,),query=True,inWeight=True,outWeight=True,inAngle=True,outAngle=True)
self.itt,self.ott = cmd.keyTangent(attrpath,time=(keyTime,),query=True,inTangentType=True,outTangentType=True)
#this is purely 'clean up after maya' code. for whatever reason maya will return a tangent type of "fixed" even though its a completely invalid tangent type... not sure what its supposed to map to, so I'm just assuming spline
if self.itt == 'fixed': self.itt = 'spline'
if self.ott == 'fixed': self.ott = 'spline'
else:
self.value = cmd.keyframe(attrpath,time=(keyTime,),query=True,eval=True,valueChange=True)
index = self.index
previousOutTT = None
previousOutTW = None
nextInTT = None
nextInTW = None
if index > 1:
previousOutTT = cmd.keyTangent(attrpath,index=(index-1,),query=True,outTangentType=True)
previousOutTW = cmd.keyTangent(attrpath,index=(index-1,),query=True,outWeight=True)
else:
previousOutTT = cmd.keyTangent(attrpath,index=(index,),query=True,outTangentType=True)
previousOutTW = cmd.keyTangent(attrpath,index=(index,),query=True,outWeight=True)
if index < cmd.keyframe(self.attr,query=True,keyframeCount=True):
nextInTT = cmd.keyTangent(attrpath,index=(index+1,),query=True,inTangentType=True)
nextInTW = cmd.keyTangent(attrpath,index=(index+1,),query=True,inWeight=True)
else:
nextInTT = cmd.keyTangent(attrpath,index=(index,),query=True,inTangentType=True)
nextInTW = cmd.keyTangent(attrpath,index=(index,),query=True,inWeight=True)
#now average the tangents
self.iw = self.ow = (previousOutTW + nextInTW )/2
示例12: export
def export(anim_curve):
"""Creates a dictionary of all the data necessary to rebuild the
curve."""
# Check the curve exists and is an animation curve.
if not cmds.objExists(anim_curve):
cmds.error("Failed to find anim curve {0}".format(anim_curve))
type = cmds.nodeType(anim_curve)
if not is_type_exportable(type):
cmds.error("Node {0} is not an anim curve".format(anim_curve))
# Get the keys on the curve.
keys = cmds.keyframe(anim_curve, query=True)
key_count = cmds.keyframe(anim_curve,
keyframeCount=True,
query=True)
# Gather the value and in/out tangent type, and x,y coordinates of
# each key.
data = {'name':anim_curve,'type':type}
data['key_data'] = [key_info_by_index(anim_curve, i)
for i in range(key_count)]
# Get infinity values
data['pre'] = cmds.getAttr("{0}.preInfinity".format(anim_curve))
data['post'] = cmds.getAttr("{0}.postInfinity".format(anim_curve))
# Get curve colour values
data['useColor'] = cmds.getAttr("{0}.useCurveColor".format(
anim_curve))
data['color'] = cmds.getAttr("{0}.curveColor".format(anim_curve))[0]
return data
示例13: __init__
def __init__(self,
name='mlBreakdownDraggerContext',
minValue=None,
maxValue=None,
defaultValue=0,
title = 'Breakdown'):
self.keySel = utl.KeySelection()
if self.keySel.selectedKeys():
pass
elif self.keySel.visibleInGraphEditor():
self.keySel.setKeyframe()
elif self.keySel.keyedChannels():
self.keySel.setKeyframe()
if not self.keySel.curves:
return
utl.Dragger.__init__(self, defaultValue=defaultValue, minValue=minValue, maxValue=maxValue, name=name, title=title)
#setup tangent type
itt,ott = utl.getHoldTangentType()
self.time = dict()
self.value = dict()
self.next = dict()
self.prev = dict()
self.average = dict()
for curve in self.keySel.curves:
if self.keySel.selected:
self.time[curve] = mc.keyframe(curve, query=True, timeChange=True, sl=True)
self.value[curve] = mc.keyframe(curve, query=True, valueChange=True, sl=True)
else:
self.time[curve] = self.keySel.time
self.value[curve] = mc.keyframe(curve, time=self.keySel.time, query=True, valueChange=True)
self.next[curve] = list()
self.prev[curve] = list()
self.average[curve] = list()
for i in self.time[curve]:
next = mc.findKeyframe(curve, time=(i,), which='next')
prev = mc.findKeyframe(curve, time=(i,), which='previous')
n = mc.keyframe(curve, time=(next,), query=True, valueChange=True)[0]
p = mc.keyframe(curve, time=(prev,), query=True, valueChange=True)[0]
self.next[curve].append(n)
self.prev[curve].append(p)
self.average[curve].append((n+p)/2)
#set the tangents on this key, and the next and previous, so they flatten properly
mc.keyTangent(curve, time=(i,), itt=itt, ott=ott)
mc.keyTangent(curve, time=(next,), itt=itt)
mc.keyTangent(curve, time=(prev,), ott=ott)
self.setTool()
self.drawString('Left: Weight Prev/Next, Middle: Weight Average')
OpenMaya.MGlobal.displayWarning('Left: Weight Prev/Next, Middle: Weight Average')
示例14: getMinMax
def getMinMax():
rangeStart = cmds.playbackOptions(query=True, minTime=True)
rangeEnd = cmds.playbackOptions(query=True, maxTime=True)
curvesShown = cmds.animCurveEditor( 'graphEditor1GraphEd', query=True, curvesShown=True)
keysTimes = []
keysValues = []
keysShown = []
if curvesShown:
for aCurve in curvesShown:
keysTimes.extend(cmds.keyframe(aCurve, query=True, timeChange=True))
keysValues.extend(cmds.keyframe(aCurve, query=True, valueChange=True))
for n, key in enumerate(keysTimes):
if rangeStart <= key <= rangeEnd:
keysShown.append(keysValues[n])
keyMax = max(keysShown)
keyMin = min(keysShown)
total = keyMax - keyMin
if total == 0: total = 1
border = total * .1
return [keyMax+border, keyMin-border]
else:
return [0, 100]
示例15: returnSetDrivenCurveInfo
def returnSetDrivenCurveInfo(driverAttribute,drivenObject):
"""
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DESCRIPTION:
Returns the info for a sdk curve
ARGUMENTS:
driverAttribute(string)
drivenObject(string)
RETURNS:
curveInfo(dict){time:value,etc...}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"""
driverCurve = returnDriverCurve(driverAttribute,drivenObject)
if driverCurve:
setDrivenCurveInfo = {}
keyCnt = mc.keyframe(driverCurve[0],q=True, keyframeCount = True)
curveValues = mc.keyframe(driverCurve[0],q=True, vc=True)
for cnt in range(keyCnt):
# Because maya is stupid and the syntax for this in pythong unfathomable my mere mortals such as I
mel.eval('string $animCurve = "%s";' %driverCurve[0])
mel.eval('int $cnt = %i;' %cnt)
keyTimeValue = mel.eval('keyframe -index $cnt -query -fc $animCurve')
setDrivenCurveInfo[keyTimeValue[0]] = (curveValues[cnt])
return setDrivenCurveInfo