Created
August 22, 2017 05:27
-
-
Save patwooky/bf85adc7f84bb281b0afa90898c68fca to your computer and use it in GitHub Desktop.
ReSpeed keyframe Timings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Problem: | |
keyframes from camera tx, ty, tz, rx, ry, rz ranging from 1001 to 1195 | |
need to have their timing remapped, such that the new timing is sped up by 2x | |
thus, the formula where kT = original frame, is ((kT - 1001) * 0.5) + 1001 | |
This will give us new keyframes from frames 1001 - 1098. | |
New frame range after re-speed is 1001 - 1093, we just truncate frames 1094 - 1098. | |
''' | |
from pymel.core import * | |
kfList = listConnections('VFX_0081_8220_Cam', plugs=False, type='animCurve') | |
for kf in kfList: | |
print ('kf is {}'.format(kf)) | |
# keyframe(kf, q=True, a=True, tc=True, vc=True) gets a list of key time/value tuples. | |
for idx, k in enumerate(keyframe(kf, q=True, a=True, tc=True, vc=True)): | |
print 'idx is {}, keyframe is {}'.format(idx, repr(k)) | |
kTime = k[0] | |
kTimeNew = ((kTime - 1001) * 0.5) + 1001 | |
print 'new time is {}'.format(kTimeNew) | |
keyframe(kf, e=True, index=idx, a=True, tc=kTimeNew) | |
print keyframe(kf, q=True, index=idx, tc=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that there's also the
scaleKeys
command which also takes into account weighted curves, tangents, etc.Also, to query keys of an object you can also use the
maya.cmds.keys
command to query to avoid the need forlistConnections
. Note thatlistConnections
defaults to also listing out connections (outputs) and thus your code could also "shift keys" for those that are related to driven keyframes (Set Driven Keyframe).Anyway, good to see these gists public! Keep on sharing.