Advertisement
Guest User

Untitled

a guest
Nov 16th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. import bpy, math
  2.  
  3. CYCLES      = 3 # how many times to bob
  4. SPEED       = 25 # how many frames between keyframes (higher is slower)
  5. LOC_AMOUNT  = 0.9 # in blender units, so numbers are generally small
  6. LOC_MATRIX  = (0, 0, 1)
  7. ROT_AMOUNT  = 0.3 # in radians
  8. ROT_MATRIX  = (0, 1, 0) # x, y, z axis (type in values less than one to get small rotations along an axis)
  9. PHASE_SHIFT = 0.5 #phase shifting the rotation
  10.  
  11. def tup_mult(coefficient, matrix):
  12.     new_matrix = []
  13.     for i in matrix:
  14.         new_matrix.append(i*coefficient)
  15.     return tuple(new_matrix)
  16.  
  17. def tup_add(tup1, tup2):
  18.     return tuple(map(sum, zip(tup1, tup2)))
  19.  
  20. cf = bpy.context.scene.frame_current
  21.  
  22. ob = bpy.context.active_object
  23.  
  24. loc = ob.location[:]
  25.  
  26. ob.location = tup_add(loc, tup_mult(-5, LOC_MATRIX))
  27. bpy.ops.anim.keyframe_insert_menu(type='Location')
  28. bpy.ops.transform.rotate(value=(ROT_AMOUNT*0.5), axis=ROT_MATRIX)
  29. bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
  30.  
  31. bpy.context.scene.frame_set(cf + ((CYCLES+0.5)*2*SPEED))
  32. ob.location = tup_add(loc, tup_mult(5, LOC_MATRIX))
  33. bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success = True)
  34. bpy.ops.transform.rotate(value=(-ROT_AMOUNT), axis=ROT_MATRIX)
  35. bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
  36.  
  37. for i in range(CYCLES):
  38.     cf += SPEED
  39.     bpy.context.scene.frame_set(cf)
  40.     ob.location = tup_add(loc, tup_mult(LOC_AMOUNT*0.5, LOC_MATRIX))
  41.     bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success = True)
  42.     bpy.context.scene.frame_set(cf+int(SPEED*PHASE_SHIFT))
  43.     bpy.ops.transform.rotate(value=(ROT_AMOUNT*-1), axis=ROT_MATRIX)
  44.     bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
  45.     cf += SPEED
  46.     bpy.context.scene.frame_set(cf)
  47.     ob.location = tup_add(loc, tup_mult(LOC_AMOUNT*-0.5, LOC_MATRIX))
  48.     bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success = True)
  49.     bpy.context.scene.frame_set(cf+int(SPEED*PHASE_SHIFT))
  50.     bpy.ops.transform.rotate(value=(ROT_AMOUNT*1), axis=ROT_MATRIX)
  51.     bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement