Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy, math
- CYCLES = 3 # how many times to bob
- SPEED = 25 # how many frames between keyframes (higher is slower)
- LOC_AMOUNT = 0.9 # in blender units, so numbers are generally small
- LOC_MATRIX = (0, 0, 1)
- ROT_AMOUNT = 0.3 # in radians
- ROT_MATRIX = (0, 1, 0) # x, y, z axis (type in values less than one to get small rotations along an axis)
- PHASE_SHIFT = 0.5 #phase shifting the rotation
- def tup_mult(coefficient, matrix):
- new_matrix = []
- for i in matrix:
- new_matrix.append(i*coefficient)
- return tuple(new_matrix)
- def tup_add(tup1, tup2):
- return tuple(map(sum, zip(tup1, tup2)))
- cf = bpy.context.scene.frame_current
- ob = bpy.context.active_object
- loc = ob.location[:]
- ob.location = tup_add(loc, tup_mult(-5, LOC_MATRIX))
- bpy.ops.anim.keyframe_insert_menu(type='Location')
- bpy.ops.transform.rotate(value=(ROT_AMOUNT*0.5), axis=ROT_MATRIX)
- bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
- bpy.context.scene.frame_set(cf + ((CYCLES+0.5)*2*SPEED))
- ob.location = tup_add(loc, tup_mult(5, LOC_MATRIX))
- bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success = True)
- bpy.ops.transform.rotate(value=(-ROT_AMOUNT), axis=ROT_MATRIX)
- bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
- for i in range(CYCLES):
- cf += SPEED
- bpy.context.scene.frame_set(cf)
- ob.location = tup_add(loc, tup_mult(LOC_AMOUNT*0.5, LOC_MATRIX))
- bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success = True)
- bpy.context.scene.frame_set(cf+int(SPEED*PHASE_SHIFT))
- bpy.ops.transform.rotate(value=(ROT_AMOUNT*-1), axis=ROT_MATRIX)
- bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
- cf += SPEED
- bpy.context.scene.frame_set(cf)
- ob.location = tup_add(loc, tup_mult(LOC_AMOUNT*-0.5, LOC_MATRIX))
- bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success = True)
- bpy.context.scene.frame_set(cf+int(SPEED*PHASE_SHIFT))
- bpy.ops.transform.rotate(value=(ROT_AMOUNT*1), axis=ROT_MATRIX)
- bpy.ops.anim.keyframe_insert_menu(type='Rotation', confirm_success = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement