Friday, June 1, 2012

unTimeWarp for Maya

Soooo, no option to bake a timewarp?! ARGHHHHHH

Here is a quick python script to bake the timewarp to a selection of items.


import maya.cmds as cmds

objects = cmds.ls(sl = True)
tRange = [ cmds.playbackOptions(q = True, minTime = True), cmds.playbackOptions(q = True, maxTime = True) ]
print tRange

dObjects = []

for obj in objects:
    dup = cmds.duplicate(obj, name = obj + "_unWarped")
    dObjects.append( dup[0] )

for x in range( tRange[0], tRange[1] + 1 ):
    cmds.currentTime(x)
    outTime = cmds.getAttr( 'time1.outTime' )
    unwarpedTime = cmds.getAttr( 'time1.unwarpedTime' )
    
    for y in range(len(objects)):
        rot = cmds.getAttr( objects[y] + ".rotate", t = outTime )
        trans = cmds.getAttr( objects[y] + ".translate", t = outTime )
        scale = cmds.getAttr( objects[y] + ".scale", t = outTime )
        
        cmds.xform( dObjects[y], t = trans[0], ro = rot[0], s = scale[0])
        cmds.setKeyframe( dObjects[y], time = unwarpedTime )

This is not a flawless method, for certain objects that have their animation keyed up chain on groups, you probably need to bake that down before running this script, or select the group and not the object directly.

No comments:

Post a Comment