本文整理汇总了Python中pymel.core.setKeyframe函数的典型用法代码示例。如果您正苦于以下问题:Python setKeyframe函数的具体用法?Python setKeyframe怎么用?Python setKeyframe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setKeyframe函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
cmds.file(new=1, f=1)
self.cube = cmds.polyCube()[0]
for i in xrange(1,21,2):
cmds.currentTime(i)
pm.setAttr(self.cube + '.tx', i)
pm.setKeyframe(self.cube + '.tx')
示例2: fixedSeed
def fixedSeed():
sel = pm.selected()
animStartTime = pm.playbackOptions(animationStartTime=1, q=1)
animEndTime = pm.playbackOptions(animationEndTime=1, q=1)
for attr in sel:
animStartTime = pm.playbackOptions(animationStartTime=1, q=1)
animEndTime = pm.playbackOptions(animationEndTime=1, q=1)
xVal = attr.rotateX.get()
yVal = attr.rotateY.get()
zVal = attr.rotateZ.get()
print animStartTime
print animEndTime
print xVal
print yVal
print zVal
while animStartTime<=animEndTime:
attr.rotateX.set(xVal+random.uniform(-.1,.1))
attr.rotateY.set(yVal+random.uniform(-.1,.1))
attr.rotateZ.set(zVal+random.uniform(-.1,.1))
pm.setKeyframe(attribute="rotate", time=animStartTime)
animStartTime+=1
示例3: testGDuplicateStandin
def testGDuplicateStandin(self):
self.standIn = pm.ls('testStandin_standInCtrl')[0]
pm.select(self.standIn)
self.cc.duplicateStandin()
pm.setKeyframe('controllerB.testSrc', t=1, v=1.5)
self.cc.saveState()
# now cache that standin too
self.cc.cacheStandin()
示例4: rigCurveShapeControl
def rigCurveShapeControl( ctrl=None, attr=None, sampleParams=[0,1,2,3,4,5,6,7,8,9,10], container=False ):
'''
스쿼시 스트레치시 그래프 에디터 커브로 쉐입을 조정하려고 만들어짐.
powAttr = rigCurveShapeControl( ctrl='spinCtrl', attr='sideAxisScaleShape', sampleParams=range( len(joints) ) )
@param ctrl:
@param attr:
@param sampleParams:
@param container:
@return: ctrl.results 어트리뷰트를 리턴함.
@rtype: pm.Attribute
'''
if not ctrl:
sel = pm.selected()
if sel:
ctrl = sel[0]
else:
return
if not attr:
attr = 'curveCtrl'
ctrl.addAttr( attr, keyable=True )
ctrl = pm.PyNode(ctrl)
ctrlAttr = pm.Attribute( ctrl.attr(attr) )
# 애니메이션 커브 생성
pm.setKeyframe( ctrlAttr, t=sampleParams[ 0], v=0)
pm.setKeyframe( ctrlAttr, t=sampleParams[-1], v=0)
pm. keyTangent( ctrlAttr, weightedTangents=True )
pm. keyTangent( ctrlAttr, weightLock=False )
pm. keyTangent( ctrlAttr, e=True, absolute=True, time=[sampleParams[ 0]], outAngle=77, outWeight=1 )
pm. keyTangent( ctrlAttr, e=True, absolute=True, time=[sampleParams[-1]], inAngle=-77, inWeight=1 )
# frameCache노드로 애니메이션 커브의 각 포인트에서 값을 가져옴
ctrl.addAttr( 'samples', multi=True, readable=True, indexMatters=False )
ctrl.addAttr( 'results', multi=True, readable=True, indexMatters=False )
frameCaches = []
for i,param in enumerate(sampleParams):
ctrl.samples[i].set( param )
frameCache = pm.createNode( 'frameCache' )
pm.connectAttr( ctrlAttr, frameCache.stream)
pm.connectAttr( ctrl.samples[i], frameCache.varyTime )
pm.connectAttr( frameCache.varying, ctrl.results, na=True)
frameCaches.append(frameCache)
# container Setting : wip
if container:
cont = pm.container( type='dagContainer', addNode=frameCaches )
cont.blackBox.set(True)
return ctrl.results
示例5: model_screenshot
def model_screenshot(selected=True, debug=False, centerCam=False):
meshes = pm.ls(sl=True)
cam = pm.camera(n='tempCam')
hfv=cam[1].getHorizontalFieldOfView()
vfv=cam[1].getVerticalFieldOfView()
grp = pm.group(em=True, n='tempCamOffset_GRP')
#Determine the selection
if selected==False:
meshes = [mesh.getParent() for mesh in pm.ls(type=pm.nt.Mesh)]
print meshes
boundingBox = pm.polyEvaluate(meshes, b=True)
#Determine the positions of the bounding box as variables
xmin=boundingBox[0][0]
xmax=boundingBox[0][1]
ymin=boundingBox[1][0]
ymax=boundingBox[1][1]
zmin=boundingBox[2][0]
zmax=boundingBox[2][1]
#get the midpoints (these are also the object center!)
zmid=(zmin+zmax)/2
ymid=(ymin+ymax)/2
xmid=(xmin+xmax)/2
# Create locators to visualize the bounding box
locators=[]
locators.append(pm.spaceLocator(n='xmin',p=[xmin,ymid,zmid]))
locators.append(pm.spaceLocator(n='xmax',p=[xmax,ymid,zmid]))
locators.append(pm.spaceLocator(n='ymin',p=[xmid,ymin,zmid]))
locators.append(pm.spaceLocator(n='ymax',p=[xmid,ymax,zmid]))
locators.append(pm.spaceLocator(n='zmin',p=[xmid,ymid,zmin]))
locators.append(pm.spaceLocator(n='zmax',p=[xmid,ymid,zmax]))
#Determine the furthest distance needed from the object
h_dist=(math.tan(hfv)*abs(xmin-xmax)) + abs(zmin-zmax)
zh_dist=(math.tan(vfv)*abs(zmin-zmax)) + abs(zmin-zmax)
zv_dist=(math.tan(vfv)*abs(zmin-zmax)) + abs(zmin-zmax)
v_dist=(math.tan(vfv)*abs(ymin-ymax)) + abs(zmin-zmax) #this will never be used, always going to be shortest.
#set the camera distance etc for the bounding box.
print h_dist,v_dist,zh_dist, zv_dist
print max(h_dist,v_dist,zh_dist, zv_dist)
cam[0].translateZ.set(max(h_dist,zh_dist,v_dist,zv_dist))
cam[0].translateY.set(ymid)
cam[0].setParent(grp)
if debug:
pm.delete(locators)
if centerCam:
grp.translate.set([zmid,0,xmid])
pm.setKeyframe(grp.rotateY, t=pm.playbackOptions(q=True,ast=True), v=0)
pm.setKeyframe(grp.rotateY, t=pm.playbackOptions(q=True,aet=True), v=360)
示例6: test_RigCtrl
def test_RigCtrl(self):
from classRigCtrl import RigCtrl
from omtk.libs import libSerialization
log.info("test_RigCtrl")
foo = RigCtrl()
foo.build()
pymel.setKeyframe(foo.node)
foo.unbuild()
network = libSerialization.export_network(foo)
pymel.select(network)
foo.build()
示例7: bdCleanKeyframes
def bdCleanKeyframes():
start = pm.playbackOptions(q=1,ast=1)
end = pm.playbackOptions(q=1,aet=1)
sel = pm.ls(sl=1,type='transform')
for i in range(8,end-10,1):
if not (i%4):
print i
pm.currentTime(i)
pm.setKeyframe(sel,t=i)
else:
pm.cutKey(sel,clear=1,an='objects',iub=0,t=(i,i+1))
示例8: bdSwitchCBLidParent
def bdSwitchCBLidParent(self,newParent):
selection = pm.ls(sl=1,type='transform')
if selection:
pass
else:
pm.warning('Nothing selected !!!')
return
if 'candybox_lid' in selection[0].name():
candyboxLidCtrl = selection[0]
try:
currentParent = candyboxLidCtrl.attr('parent').get()
except:
pm.warning('Current selection has no Parent attribute, aborting!')
return
print currentParent
switchFrame = pm.currentTime(q=1)
pm.currentTime(switchFrame-1,e=1)
pm.setKeyframe(candyboxLidCtrl)
pm.currentTime(switchFrame,e=1)
hatPos = candyboxLidCtrl.getTranslation(space='world')
hatRot = candyboxLidCtrl.getRotation(space='world')
#World Parent
if newParent == 0:
print 'Candybox new parent: Candybox'
candyboxLidCtrl.attr('parent').set(0)
elif newParent == 2:
print 'Candybox new parent: Right Hand'
candyboxLidCtrl.attr('parent').set(2)
elif newParent == 1:
print 'Candybox new parent: Left Hand'
candyboxLidCtrl.attr('parent').set(1)
candyboxLidCtrl.setTranslation(hatPos,space='world')
candyboxLidCtrl.setRotation(hatRot,space='world')
pm.setKeyframe(candyboxLidCtrl )
else:
pm.warning('Select candybox_lid_ctrl')
示例9: animateSpotLights
def animateSpotLights():
spotLights=cmds.ls(type='spotLight')
for spotL in spotLights:
#lights turn off at this time
randomFrameOff = random.randrange(530,535)
step = 20
randomFrameOn = randomFrameOff + step
#lights turn on at this time
randomFrameOn2 = random.randrange(900,905)
randomFrameOff2 = randomFrameOn2 + step
#set attributes for light turned off
pm.setAttr(spotL + '.intensity',0)
pm.setAttr(spotL + '.aiExposure',0)
pm.setAttr(propLight + '.color',1, 0.897, 0.667)
keyableAttributes = ['aiExposure','intensity']
#keyframe it
pm.setKeyframe(spotL,at=keyableAttributes,t=randomFrameOff)
#set attributes for light turned on
pm.setAttr(spotL + '.intensity',1)
pm.setAttr(spotL + '.aiExposure',10)
#keyframe it
pm.setKeyframe(spotL,at=keyableAttributes,t=randomFrameOn)
#keyframe the other time when it's time to turn off
pm.setKeyframe(spotL,at=keyableAttributes, t=randomFrameOn2)
#turn the lights off
pm.setAttr(spotL + '.intensity',0)
pm.setAttr(spotL + '.aiExposure',0)
#keyframe it
pm.setKeyframe(spotL,at=keyableAttributes, t=randomFrameOff2)
print 'spot is animated out of this light!!!'
示例10: matchIkToFk
def matchIkToFk(ikControl, ikPole, offset=100.0, msgAttr='fkjoints', autoKey=True):
"""
Matches ikControl and ikPole Vector control to match the current pose of underlying
fk duplicate joint chains
Finds the fk joints using a previously created message connection to the attribute msgAttr
"""
fkJoints = pmc.listConnections('{0}.{1}'.format(ikControl, msgAttr),
destination=False, source=True)
attr = pmc.listConnections('{0}.ikfk'.format(ikControl), destination=False,
source=True, plugs=True, scn=True)[0]
switchControl = attr.node()
switchAttr = attr.name(includeNode=False)
frameBeforeCurrent = pmc.currentTime(q=True) - 1
if autoKey:
pmc.setKeyframe(switchControl, attribute=switchAttr, time=frameBeforeCurrent,
value=1, outTangentType='step')
pmc.setKeyframe([ikControl, ikPole], time=frameBeforeCurrent, outTangentType='step')
pmc.setKeyframe(switchControl, attribute=switchAttr, value=0, outTangentType='step')
alignObjects(ikControl, fkJoints[-1])
loc = getPoleVectorPosition(fkJoints, offset, curveGuide=False)
alignObjects(ikPole, loc, position=True, rotation=False)
pmc.delete(loc)
if autoKey:
pmc.setKeyframe([ikControl, ikPole], time=frameBeforeCurrent)
pmc.headsUpMessage('BAMF!')
示例11: insert_key
def insert_key(self, attr, value):
'''
# this inserts a key at the given position
# take the attr to key and the position in time
# attr example: 'pCube1.translateX'
'''
print attr, value.getValue(), attr, value.getValue()
pm.setKeyframe('%s' % (attr), time= int(value.getValue()) )
# reinvoking the create to add the uis for the new keys
print 'recreating'
pm.deleteUI(self.temp_layout)
self.create()
示例12: amcveRebuild
def amcveRebuild(cvNew, cvSrcProfile):
"""
"""
cvTrimmed = cvSrcProfile['cvTrimmed']
cvBaseMod = cvSrcProfile['cvBaseMod']
cvPortray = cvSrcProfile['cvPortray']
cvFeature = cvSrcProfile['cvFeature']
''' A. create animCurve '''
# create same type of animation curve
cvNew = pm.createNode(cvBaseMod['cvTyp'], n= cvNew)
''' B. build curve base '''
# whatever this animationCurve is time-base or float-base,
# one of lists will be empty, just add them up.
cvInp = cvPortray['Frame'] + cvPortray['Float']
# set value to each keyframe
for i, x in enumerate(cvInp):
if cvTrimmed and (x < cvTrimmed[0] or x > cvTrimmed[1]):
continue
# whatever this animationCurve is time-base or float-base,
# just set both, the one incorrect will take no effect.
y = cvPortray['Value'][i]
isBD = True if x in cvBaseMod['breaD'] else False
pm.setKeyframe(cvNew, t= x, f= x, v= y, bd= isBD)
''' C. inject curve feature '''
cvNew.setPreInfinityType(cvBaseMod['prInf'])
cvNew.setPostInfinityType(cvBaseMod['poInf'])
weedT = cvBaseMod['weedT'][0]
pm.keyTangent(cvNew, wt= weedT)
if weedT:
for i, x in enumerate(cvInp):
if cvTrimmed and (x < cvTrimmed[0] or x > cvTrimmed[1]):
continue
WLock = cvFeature['WLock'][i]
pm.keyTangent(cvNew, index= [i], wl= WLock)
for i, x in enumerate(cvInp):
if cvTrimmed and (x < cvTrimmed[0] or x > cvTrimmed[1]):
continue
pm.keyTangent(cvNew, index= [i], l= cvFeature['TLock'][i])
pm.keyTangent(cvNew, index= [i], iw= cvFeature['InWet'][i])
pm.keyTangent(cvNew, index= [i], ow= cvFeature['OuWet'][i])
pm.keyTangent(cvNew, index= [i], ia= cvFeature['InAng'][i])
pm.keyTangent(cvNew, index= [i], oa= cvFeature['OuAng'][i])
pm.keyTangent(cvNew, index= [i], itt= cvFeature['InTyp'][i])
pm.keyTangent(cvNew, index= [i], ott= cvFeature['OuTyp'][i])
return cvNew
示例13: slice
def slice(self, slices_in_x, slices_in_y):
"""slices all renderable cameras
"""
# set render resolution
self.unslice_scene()
self.is_sliced = True
self._store_data()
sx = self.slices_in_x = slices_in_x
sy = self.slices_in_y = slices_in_y
# set render resolution
d_res = pm.PyNode("defaultResolution")
h_res = d_res.width.get()
v_res = d_res.height.get()
# this system only works when the
d_res.aspectLock.set(0)
d_res.pixelAspect.set(1)
d_res.width.set(h_res / float(sx))
d_res.pixelAspect.set(1)
d_res.height.set(v_res / float(sy))
d_res.pixelAspect.set(1)
# use h_aperture to calculate v_aperture
h_aperture = self.camera.getAttr('horizontalFilmAperture')
# recalculate the other aperture
v_aperture = h_aperture * v_res / h_res
self.camera.setAttr('verticalFilmAperture', v_aperture)
v_aperture = self.camera.getAttr('verticalFilmAperture')
self.camera.setAttr('zoom', 1.0/float(sx))
t = 0
for i in range(sy):
v_pan = v_aperture / (2.0 * sy) * (1 + 2 * i - sy)
for j in range(sx):
h_pan = h_aperture / (2.0 * sx) * (1 + 2 * j - sx)
pm.currentTime(t)
pm.setKeyframe(self.camera, at='horizontalPan', v=h_pan)
pm.setKeyframe(self.camera, at='verticalPan', v=v_pan)
t += 1
self.camera.panZoomEnabled.set(1)
self.camera.renderPanZoom.set(1)
d_res.pixelAspect.set(1)
示例14: random
def random():
sel = pm.selected()
animStartTime = pm.playbackOptions(animationStartTime=1, q=1)
animEndTime = pm.playbackOptions(animationEndTime=1, q=1)
while animStartTime<=animEndTime:
for s in sel:
s.translateX.set(s.translateX.get()+random.uniform(-.1,.1))
s.translateY.set(s.translateY.get()+random.uniform(-.1,.1))
s.translateZ.set(s.translateZ.get()+random.uniform(-.1,.1))
pm.setKeyframe(attribute="translate", time=animStartTime)
animStartTime+=1
示例15: copyAnim
def copyAnim():
selection = pm.ls(sl=True)
if len(selection) != 2:
pm.warning('Need exactly two objects to copy')
return
try:
namespace = selection[0].namespace()
except:
namespace = ''
print namespace
holders = pm.ls('*_HOLDE*')
if namespace != '':
holders = pm.ls('*:*_HOLDE*')
if holders:
pm.delete(holders)
source = selection[0]
target = selection[1]
pm.setKeyframe(source)
pm.setKeyframe(target)
sourceName = source.name()
targetName = target.name()
if namespace != '':
sourceName = source.stripNamespace()
targetName = target.stripNamespace()
pm.select(cl=True)
sourceAttr = pm.listAttr(source,k=True)
sourceHolder = pm.group(n=namespace + sourceName + '_SOURCE_HOLDER')
for attr in sourceAttr:
attrType = source.attr(attr).type()
pm.addAttr(sourceHolder,ln='__' + attr,nn=attr,at = attrType)
sourceHolder.attr('__' + attr).set(source.attr(attr).get())
pm.select(cl=True)
targetAttr = pm.listAttr(target,k=True)
targetHolder = pm.group(n=namespace + targetName + '_TARGET_HOLDER')
for attr in targetAttr:
attrType = target.attr(attr).type()
pm.addAttr(targetHolder,ln='__' + attr,nn=attr,at = attrType)
targetHolder.attr('__' + attr).set(target.attr(attr).get())
pm.select([target,source])