def tangentScale(value, outValue=None):
if outValue == None:
outValue = value
curves = None
#order of operations:
#selected keys, visible in graph editor on current frame
selected = False
time = mc.currentTime(query=True)
curves = mc.keyframe(query=True, name=True, selected=True)
if curves:
#try selected keys first
selected = True
else:
#then visible in graph editor
graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)
if graphVis:
curves = mc.keyframe(graphVis, query=True, name=True)
else:
#otherwise try keyed channels.
sel = mc.ls(sl=True)
if not sel:
return
curves = mc.listConnections(sel, s=True, d=False, type='animCurve')
if not curves:
return
for curve in curves:
keyTimes = list()
#set tangents weighted if they aren't already
if mc.keyTangent(curve, query=True, weightedTangents=True):
mc.keyTangent(curve, edit=True, weightedTangents=True)
if selected:
keyTimes = mc.keyframe(curve, query=True, timeChange=True, selected=True)
else:
keyTimes = [time]
for t in keyTimes:
weight = mc.keyTangent(curve, time=(t,), query=True, inWeight=True, outWeight=True)
if not weight:
continue
inOut = list()
for w,v in zip(weight,[value,outValue]):
if v<1 and w < 0.1:
inOut.append(0)
elif v>1 and w == 0:
inOut.append(0.1)
else:
inOut.append(w*v)
mc.keyTangent(curve, time=(t,), edit=True, absolute=True, inWeight=inOut[0], outWeight=inOut[1])
评论列表
文章目录