Local timewarps for animated objects
- September 1st, 2014
- Posted in Maya
- Write comment
Sure, scene timewarp is cool, but what if you want to just timewarp a few objects (say, your tracked camera)??
Select the objects that you want to timewarp, and run this script. Any animation curves on your selection will have a new animCurve node plugged into their “time” input, that you can tweak to timewarp your animation.
def makeWarpCurve(): timeWarpNode = cmds.createNode('animCurveTT', name='timeWarper1') startTime= cmds.playbackOptions( q=True, min=True) endTime= cmds.playbackOptions( q=True, max=True) cmds.setAttr(timeWarpNode + '.preInfinity', 1) cmds.setAttr(timeWarpNode + '.postInfinity', 1) cmds.addAttr(timeWarpNode, ln='isTimeWarp', at='bool') cmds.setKeyframe(timeWarpNode, time=(startTime,), insert=True) cmds.setKeyframe(timeWarpNode, time=(endTime,), insert=True) cmds.keyframe(timeWarpNode, index=(0,), absolute=True, valueChange=startTime) cmds.keyframe(timeWarpNode, index=(1,), absolute=True, valueChange=endTime) cmds.keyTangent(timeWarpNode, index=(0,), itt='linear', ott='linear') cmds.keyTangent(timeWarpNode, index=(1,), itt='linear', ott='linear') return timeWarpNode def applyTimeWarp(objects, warpCurve=None): if not warpCurve: warpCurve = makeWarpCurve() else: if not cmds.objExists(warpCurve): print 'Cannot find warpCurve: "%s"' % warpCurve return for obj in objects: print obj for conn in cmds.listConnections( obj, d=False, s=True, type='animCurve'): print '\t', conn cmds.connectAttr(warpCurve + '.output', conn + '.input', force=True) return warpCurve def selectAllWarpNodes(): wn = getAllWarpNodes() if wn: cmds.select(wn) else: print 'No warp nodes found' def getAllWarpNodes(): warpNodes = cmds.ls('*.isTimeWarp', recursive=True, objectsOnly=True) return warpNodes def warpSelected(): sel = cmds.ls(sl=True) if sel: warpCurve = applyTimeWarp(sel) cmds.select(warpCurve) warpSelected()
You can have multiple timewarps in a scene. Just select each object (or group of objects) separately and make new timewarpers.
I have no idea how it interacts with scene timewarp. Probably the universe will implode on itself.
the “getAllWarpNodes()” function will return all timewarper nodes in the scene. Or do a “selectAllWarpNodes()” to select them all.