Paste Code
Paste Blends
Paste Images
bl_info = {
"name": "Bounce",
"author": "Kgeogeo",
"version": (1, 0),
"blender": (2, 6, 3),
"location": "Graph editor >> UI panel",
"description": "Make bounce",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Animation"}

import bpy
import math

class CreateBounce(bpy.types.Operator):
bl_idname = "graph.createbounce"
bl_label = "create bounce"

@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
def create_list():
l=[]
for ob in context.selected_objects:
if ob.animation_data:
action = ob.animation_data.action
for curve in [curve for curve in action.fcurves if not curve.hide]:
prev_kfp = None
for kfp in curve.keyframe_points:
if kfp.select_control_point:
l.append([(ob.name+curve.data_path),kfp,prev_kfp,False,curve])
prev_kfp = kfp
return l

def init_list(list):
for l in list:
l[3] = False

def create_bounce(list):
def factor(i):
if i[2]:
factor = (i[2].co.y-i[1].co.y)/(i[2].co.x-i[1].co.x)
else:
factor = 0
return factor

def create_modifier(list,fac_max):
for i in list:
if fac_max != 0:
amplitude = factor(i)/fac_max
else:
amplitude = 0
if amplitude != 0:
mod = i[4].modifiers.new('FNGENERATOR')
mod.use_additive = True
mod.use_restricted_range = True
mod.use_influence = True
mod.frame_end = i[1].co.x + context.object.decal
mod.frame_start = i[1].co.x
mod.blend_out = context.object.decal
mod.amplitude = amplitude * 10
mod.influence = 1/10
mod.phase_offset = 0.0

def add_in_group(j,fac_max):
j[3] = True
group.append(j)
f = factor(j)
if abs(f) > fac_max:
fac_max = abs(f)
return fac_max

for i in list:
group = []
if not i[3]:
i[3] = True
group.append(i)
fac_max = abs(factor(i))
for j in list:
if not j[3] and j[0] == i[0] and j[1].co.x == i[1].co.x:
fac_max = add_in_group(j,fac_max)
create_modifier(group,fac_max)

list = create_list()
create_bounce(list)
init_list(list)

return {'FINISHED'}

class RemoveBounce(bpy.types.Operator):
bl_idname = "graph.removebounce"
bl_label = "remove bounce"

@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
for ob in context.selected_objects:
if ob.animation_data:
action = ob.animation_data.action
for fc in [fc for fc in action.fcurves if not fc.hide]:
for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:
fc.modifiers.remove(m)

context.area.tag_redraw()
return {'FINISHED'}


class BouncedPanel(bpy.types.Panel):
bl_label = "Bounce"
bl_idname = "OBJECT_PT_hello"
bl_space_type = "GRAPH_EDITOR"
bl_region_type = "UI"

def draw(self, context):
layout = self.layout

obj = context.object
row = layout.row()
row.operator('graph.createbounce', text="Create Bounce")
row = layout.row()
row.prop(context.object,'influence', text="Influence")
row = layout.row()
row.prop(context.object,'phase_multiplier', text="Phase Multiplier")
row = layout.row()
row.prop(context.object,'phase_offset', text="Phase Offset")
row = layout.row()
row.prop(context.object,'decal', text="Decal")
row = layout.row()
row.operator('graph.removebounce', text="Remove Selected Bounce")

def update_influence(self, context):
for ob in context.selected_objects:
if ob.animation_data:
action = ob.animation_data.action
for fc in [fc for fc in action.fcurves if not fc.hide]:
for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:
m.influence = context.object.influence/10

def update_phase_offset(self, context):
for ob in context.selected_objects:
if ob.animation_data:
action = ob.animation_data.action
for fc in [fc for fc in action.fcurves if not fc.hide]:
for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:
m.phase_offset = context.object.phase_offset

def update_decal(self, context):
for ob in context.selected_objects:
if ob.animation_data:
action = ob.animation_data.action
for fc in [fc for fc in action.fcurves if not fc.hide]:
for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:
m.blend_out = context.object.decal
m.frame_end = m.frame_start + context.object.decal

def update_phase_multiplier(self, context):
for ob in context.selected_objects:
if ob.animation_data:
action = ob.animation_data.action
for fc in [fc for fc in action.fcurves if not fc.hide]:
for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:
m.phase_multiplier = context.object.phase_multiplier

def register():
bpy.utils.register_module(__name__)
bpy.types.Object.influence = bpy.props.FloatProperty(default=1.0, min=-10.0, max=10.0, update=update_influence)
bpy.types.Object.phase_offset = bpy.props.FloatProperty(default=0.0, min=-10.0, max=10.0, update=update_phase_offset)
bpy.types.Object.decal = bpy.props.IntProperty(default=5, min=0, update=update_decal)
bpy.types.Object.phase_multiplier = bpy.props.FloatProperty(default=1.0, min=-10.0, max=10.0, update=update_phase_multiplier)

def unregister():
bpy.utils.unregister_module(__name__)


if __name__ == "__main__":
register()
  1. bl_info = {
  2.     "name": "Bounce",
  3.     "author": "Kgeogeo",
  4.     "version": (1, 0),
  5.     "blender": (2, 6, 3),
  6.     "location": "Graph editor >> UI panel",
  7.     "description": "Make bounce",
  8.     "warning": "",
  9.     "wiki_url": "",
  10.     "tracker_url": "",
  11.     "category": "Animation"}
  12.  
  13. import bpy
  14. import math
  15.                              
  16. class CreateBounce(bpy.types.Operator):
  17.     bl_idname = "graph.createbounce"
  18.     bl_label = "create bounce"
  19.  
  20.     @classmethod
  21.     def poll(cls, context):
  22.         return context.active_object is not None
  23.  
  24.     def execute(self, context):
  25.         def create_list():
  26.             l=[]
  27.             for ob in context.selected_objects:              
  28.                 if ob.animation_data:
  29.                     action = ob.animation_data.action        
  30.                     for curve in [curve for curve in action.fcurves if not curve.hide]:
  31.                         prev_kfp = None
  32.                         for kfp in curve.keyframe_points:
  33.                             if kfp.select_control_point:
  34.                                 l.append([(ob.name+curve.data_path),kfp,prev_kfp,False,curve])
  35.                             prev_kfp = kfp
  36.             return l
  37.        
  38.         def init_list(list):
  39.             for l in list:
  40.                 l[3] = False
  41.  
  42.         def create_bounce(list):  
  43.             def factor(i):
  44.                 if i[2]:
  45.                     factor = (i[2].co.y-i[1].co.y)/(i[2].co.x-i[1].co.x)
  46.                 else:
  47.                     factor = 0
  48.                 return factor
  49.  
  50.             def create_modifier(list,fac_max):
  51.                 for i in list:
  52.                     if fac_max != 0:
  53.                         amplitude = factor(i)/fac_max
  54.                     else:
  55.                         amplitude = 0
  56.                     if amplitude != 0:    
  57.                         mod = i[4].modifiers.new('FNGENERATOR')
  58.                         mod.use_additive = True
  59.                         mod.use_restricted_range = True
  60.                         mod.use_influence = True                        
  61.                         mod.frame_end = i[1].co.x + context.object.decal                        
  62.                         mod.frame_start = i[1].co.x
  63.                         mod.blend_out = context.object.decal                        
  64.                         mod.amplitude = amplitude * 10
  65.                         mod.influence = 1/10
  66.                         mod.phase_offset = 0.0  
  67.                          
  68.             def add_in_group(j,fac_max):
  69.                 j[3] = True
  70.                 group.append(j)
  71.                 f = factor(j)
  72.                 if abs(f) > fac_max:
  73.                     fac_max = abs(f)
  74.                 return fac_max    
  75.                            
  76.             for i in list:
  77.                 group = []
  78.                 if not i[3]:
  79.                     i[3] = True
  80.                     group.append(i)
  81.                     fac_max = abs(factor(i))
  82.                     for j in list:
  83.                          if not j[3] and j[0] == i[0] and j[1].co.x == i[1].co.x:
  84.                              fac_max = add_in_group(j,fac_max)
  85.                     create_modifier(group,fac_max)
  86.  
  87.         list = create_list()
  88.         create_bounce(list)        
  89.         init_list(list)
  90.                
  91.         return {'FINISHED'}
  92.  
  93. class RemoveBounce(bpy.types.Operator):
  94.     bl_idname = "graph.removebounce"
  95.     bl_label = "remove bounce"
  96.  
  97.     @classmethod
  98.     def poll(cls, context):
  99.         return context.active_object is not None
  100.  
  101.     def execute(self, context):
  102.         for ob in context.selected_objects:            
  103.             if ob.animation_data:
  104.                 action = ob.animation_data.action
  105.                 for fc in [fc for fc in action.fcurves if not fc.hide]:
  106.                     for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
  107.                         for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:
  108.                             fc.modifiers.remove(m)
  109.                            
  110.         context.area.tag_redraw()        
  111.         return {'FINISHED'}
  112.  
  113.  
  114. class BouncedPanel(bpy.types.Panel):
  115.     bl_label = "Bounce"
  116.     bl_idname = "OBJECT_PT_hello"
  117.     bl_space_type = "GRAPH_EDITOR"
  118.     bl_region_type = "UI"
  119.  
  120.     def draw(self, context):
  121.         layout = self.layout
  122.  
  123.         obj = context.object
  124.         row = layout.row()
  125.         row.operator('graph.createbounce', text="Create Bounce")
  126.         row = layout.row()
  127.         row.prop(context.object,'influence', text="Influence")
  128.         row = layout.row()
  129.         row.prop(context.object,'phase_multiplier', text="Phase Multiplier")
  130.         row = layout.row()
  131.         row.prop(context.object,'phase_offset', text="Phase Offset")
  132.         row = layout.row()
  133.         row.prop(context.object,'decal', text="Decal")
  134.         row = layout.row()
  135.         row.operator('graph.removebounce', text="Remove Selected Bounce")      
  136.  
  137. def update_influence(self, context):
  138.         for ob in context.selected_objects:              
  139.             if ob.animation_data:
  140.                 action = ob.animation_data.action
  141.                 for fc in [fc for fc in action.fcurves if not fc.hide]:
  142.                     for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
  143.                         for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:              
  144.                             m.influence = context.object.influence/10          
  145.  
  146. def update_phase_offset(self, context):
  147.         for ob in context.selected_objects:              
  148.             if ob.animation_data:
  149.                 action = ob.animation_data.action
  150.                 for fc in [fc for fc in action.fcurves if not fc.hide]:
  151.                     for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
  152.                         for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:                
  153.                             m.phase_offset = context.object.phase_offset
  154.  
  155. def update_decal(self, context):
  156.         for ob in context.selected_objects:              
  157.             if ob.animation_data:
  158.                 action = ob.animation_data.action
  159.                 for fc in [fc for fc in action.fcurves if not fc.hide]:
  160.                     for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
  161.                         for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:  
  162.                             m.blend_out = context.object.decal
  163.                             m.frame_end = m.frame_start + context.object.decal
  164.  
  165. def update_phase_multiplier(self, context):
  166.         for ob in context.selected_objects:              
  167.             if ob.animation_data:
  168.                 action = ob.animation_data.action
  169.                 for fc in [fc for fc in action.fcurves if not fc.hide]:
  170.                     for kfp in [kfp for kfp in fc.keyframe_points if kfp.select_control_point]:
  171.                         for m in [m for m in fc.modifiers if m.frame_start == kfp.co.x]:  
  172.                             m.phase_multiplier = context.object.phase_multiplier
  173.                    
  174. def register():
  175.     bpy.utils.register_module(__name__)
  176.     bpy.types.Object.influence = bpy.props.FloatProperty(default=1.0, min=-10.0, max=10.0, update=update_influence)
  177.     bpy.types.Object.phase_offset = bpy.props.FloatProperty(default=0.0, min=-10.0, max=10.0, update=update_phase_offset)
  178.     bpy.types.Object.decal = bpy.props.IntProperty(default=5, min=0, update=update_decal)
  179.     bpy.types.Object.phase_multiplier = bpy.props.FloatProperty(default=1.0, min=-10.0, max=10.0, update=update_phase_multiplier)
  180.  
  181. def unregister():
  182.     bpy.utils.unregister_module(__name__)
  183.  
  184.  
  185. if __name__ == "__main__":
  186.     register()
go to heaven