def __init__(self, startFrame=0, endFrame=None, addMarkers=True, roundTo=2): ''' Initializes the stopwatch. ''' self.frameRate = utl.getFrameRate() self.startFrame = int(startFrame) self.endFrame = endFrame self.addMarkers = True self.roundTo = roundTo self.markTime = list()
def main(): sel = mc.ls(sl=True) if not sel: raise RuntimeError('Please select an object.') if [x for x in sel if not mc.attributeQuery('translate', exists=True, node=x)]: raise RuntimeError('Only works on transform nodes, please adjust your selection.') frameRate = utl.getFrameRate() timeFactor = 1.0/frameRate unit = mc.currentUnit(query=True, linear=True) #default is meters distFactor = 1 if unit == 'mm': distFactor = 1000 elif unit == 'cm': distFactor = 100 elif unit == 'km': distFactor = 0.001 elif unit == 'in': distFactor = 39.3701 elif unit == 'ft': distFactor = 3.28084 elif unit == 'yd': distFactor = 1.09361 elif unit == 'mi': distFactor = 0.000621371 g = 9.8 * distFactor start, end = utl.frameRange() start = int(start) end = int(end) mc.currentTime(start) for each in sel: mc.setKeyframe(each+'.translate') startTrans = mc.getAttr(each+'.translate')[0] prevTrans = [mc.keyframe(each, query=True, attribute=x, eval=True, time=(start-1,))[0] for x in ('tx','ty','tz')] xInit = startTrans[0]-prevTrans[0] yInit = startTrans[1]-prevTrans[1] zInit = startTrans[2]-prevTrans[2] mc.cutKey(each, attribute='translate', time=(start+0.1,end+0.5)) mc.setKeyframe(each, attribute='translateX', time=start+1, value=startTrans[0]+xInit) mc.setKeyframe(each, attribute='translateZ', time=start+1, value=startTrans[2]+zInit) mc.setKeyframe(each, attribute='translateX', time=end-1, value=startTrans[0]+(xInit*(end-start-1))) mc.setKeyframe(each, attribute='translateZ', time=end-1, value=startTrans[2]+(zInit*(end-start-1))) mc.setKeyframe(each, attribute='translateX', time=end, value=startTrans[0]+(xInit*(end-start))) mc.setKeyframe(each, attribute='translateZ', time=end, value=startTrans[2]+(zInit*(end-start))) for i,f in enumerate(range(start,end+1)): t = i * timeFactor y = startTrans[1] + (i * yInit) - (g * t * t)/2 mc.setKeyframe(each, attribute='translateY', time=f, value=y)
def main(): sel = mc.ls(sl=True) if not sel: raise RuntimeError('Please select an object.') if [ x for x in sel if not mc.attributeQuery('translate', exists=True, node=x) ]: raise RuntimeError( 'Only works on transform nodes, please adjust your selection.') frameRate = utl.getFrameRate() timeFactor = 1.0 / frameRate unit = mc.currentUnit(query=True, linear=True) #default is meters distFactor = 1 if unit == 'mm': distFactor = 1000 elif unit == 'cm': distFactor = 100 elif unit == 'km': distFactor = 0.001 elif unit == 'in': distFactor = 39.3701 elif unit == 'ft': distFactor = 3.28084 elif unit == 'yd': distFactor = 1.09361 elif unit == 'mi': distFactor = 0.000621371 g = 9.8 * distFactor start, end = utl.frameRange() start = int(start) end = int(end) mc.currentTime(start) for each in sel: mc.setKeyframe(each + '.translate') startTrans = mc.getAttr(each + '.translate')[0] prevTrans = [ mc.keyframe(each, query=True, attribute=x, eval=True, time=(start - 1, ))[0] for x in ('tx', 'ty', 'tz') ] xInit = startTrans[0] - prevTrans[0] yInit = startTrans[1] - prevTrans[1] zInit = startTrans[2] - prevTrans[2] mc.cutKey(each, attribute='translate', time=(start + 0.1, end + 0.5)) mc.setKeyframe(each, attribute='translateX', time=start + 1, value=startTrans[0] + xInit) mc.setKeyframe(each, attribute='translateZ', time=start + 1, value=startTrans[2] + zInit) mc.setKeyframe(each, attribute='translateX', time=end - 1, value=startTrans[0] + (xInit * (end - start - 1))) mc.setKeyframe(each, attribute='translateZ', time=end - 1, value=startTrans[2] + (zInit * (end - start - 1))) mc.setKeyframe(each, attribute='translateX', time=end, value=startTrans[0] + (xInit * (end - start))) mc.setKeyframe(each, attribute='translateZ', time=end, value=startTrans[2] + (zInit * (end - start))) for i, f in enumerate(range(start, end + 1)): t = i * timeFactor y = startTrans[1] + (i * yInit) - (g * t * t) / 2 mc.setKeyframe(each, attribute='translateY', time=f, value=y)