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

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):
l = context.object.decal
for gp in context.object.animation_data.action.groups:
kfp = 0
while kfp < len(gp.channels[0].keyframe_points):
if gp.channels[0].keyframe_points[kfp].select_control_point:
for ch in range(3):
fact = ((gp.channels[ch].keyframe_points[kfp].co.y-gp.channels[ch].keyframe_points[kfp-1].co.y)/
(gp.channels[ch].keyframe_points[kfp].co.x-gp.channels[ch].keyframe_points[kfp-1].co.x))
mod = gp.channels[ch].modifiers.new("FNGENERATOR")
mod.use_additive = True
mod.use_restricted_range = True
mod.frame_end = gp.channels[ch].keyframe_points[kfp].co.x + l
mod.frame_start = gp.channels[ch].keyframe_points[kfp].co.x
mod.blend_out = l
mod.amplitude = fact*10
mod.use_influence = True
mod.influence = context.object.influence
mod.phase_offset = context.object.phase_offset
gp.channels[ch].keyframe_points[kfp].select_control_point = True
bpy.context.object.bool = True
kfp += 1


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 gp in context.object.animation_data.action.groups:
for ch in gp.channels:
for kfp in ch.keyframe_points:
try:
ch.modifiers.remove(ch.modifiers[0])
except:
do = 'nothing'

context.area.tag_redraw()
context.object.bool = False
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
if not context.object.bool:
row = layout.row()
row.operator('graph.createbounce', text="Create Bounce")
else:
row = layout.row()
row.operator('graph.removebounce', text="Remove All Bounce")
row = layout.row()
row.prop(context.object,'influence', text="Influence")
row = layout.row()
row.prop(context.object,'phase_offset', text="Phase Offset")
row = layout.row()
row.prop(context.object,'decal', text="Decal")

def update_influence(self, context):
for gp in context.object.animation_data.action.groups:
for ch in gp.channels:
for m in ch.modifiers:
m.influence = context.object.influence

def update_phase_offset(self, context):
for gp in context.object.animation_data.action.groups:
for ch in gp.channels:
for m in ch.modifiers:
m.phase_offset = context.object.phase_offset

def update_decal(self, context):
l = context.object.decal
for gp in context.object.animation_data.action.groups:
for ch in gp.channels:
for m in ch.modifiers:
m.blend_out = context.object.decal
m.frame_end = m.frame_start + context.object.decal

def register():
bpy.utils.register_module(__name__)
bpy.types.Object.influence = bpy.props.FloatProperty(default=1.0, min=0.0, max=1.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, max=50, update=update_decal)
bpy.types.Object.bool = bpy.props.BoolProperty(default=False)

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.  
  15. class CreateBounce(bpy.types.Operator):
  16.     bl_idname = "graph.createbounce"
  17.     bl_label = "create bounce"
  18.  
  19.     @classmethod
  20.     def poll(cls, context):
  21.         return context.active_object is not None
  22.  
  23.     def execute(self, context):
  24.         l = context.object.decal
  25.         for gp in context.object.animation_data.action.groups:              
  26.             kfp = 0
  27.             while kfp < len(gp.channels[0].keyframe_points):              
  28.                 if gp.channels[0].keyframe_points[kfp].select_control_point:
  29.                     for ch in range(3):
  30.                         fact = ((gp.channels[ch].keyframe_points[kfp].co.y-gp.channels[ch].keyframe_points[kfp-1].co.y)/
  31.                                 (gp.channels[ch].keyframe_points[kfp].co.x-gp.channels[ch].keyframe_points[kfp-1].co.x))
  32.                         mod = gp.channels[ch].modifiers.new("FNGENERATOR")
  33.                         mod.use_additive = True
  34.                         mod.use_restricted_range = True
  35.                         mod.frame_end = gp.channels[ch].keyframe_points[kfp].co.x + l                        
  36.                         mod.frame_start = gp.channels[ch].keyframe_points[kfp].co.x
  37.                         mod.blend_out = l
  38.                         mod.amplitude = fact*10
  39.                         mod.use_influence = True
  40.                         mod.influence = context.object.influence
  41.                         mod.phase_offset = context.object.phase_offset
  42.                         gp.channels[ch].keyframe_points[kfp].select_control_point = True
  43.                     bpy.context.object.bool = True
  44.                 kfp += 1
  45.                                    
  46.  
  47.         return {'FINISHED'}
  48.  
  49. class RemoveBounce(bpy.types.Operator):
  50.     bl_idname = "graph.removebounce"
  51.     bl_label = "remove bounce"
  52.  
  53.     @classmethod
  54.     def poll(cls, context):
  55.         return context.active_object is not None
  56.  
  57.     def execute(self, context):
  58.         for gp in context.object.animation_data.action.groups:
  59.             for ch in gp.channels:
  60.                 for kfp in ch.keyframe_points:              
  61.                     try:
  62.                         ch.modifiers.remove(ch.modifiers[0])
  63.                     except:
  64.                         do = 'nothing'
  65.                            
  66.         context.area.tag_redraw()
  67.         context.object.bool = False          
  68.         return {'FINISHED'}
  69.  
  70.  
  71. class BouncedPanel(bpy.types.Panel):
  72.     bl_label = "Bounce"
  73.     bl_idname = "OBJECT_PT_hello"
  74.     bl_space_type = "GRAPH_EDITOR"
  75.     bl_region_type = "UI"
  76.  
  77.     def draw(self, context):
  78.         layout = self.layout
  79.  
  80.         obj = context.object
  81.         if not context.object.bool:
  82.             row = layout.row()
  83.             row.operator('graph.createbounce', text="Create Bounce")
  84.         else:
  85.             row = layout.row()
  86.             row.operator('graph.removebounce', text="Remove All Bounce")
  87.             row = layout.row()
  88.             row.prop(context.object,'influence', text="Influence")
  89.             row = layout.row()
  90.             row.prop(context.object,'phase_offset', text="Phase Offset")
  91.             row = layout.row()
  92.             row.prop(context.object,'decal', text="Decal")        
  93.  
  94. def update_influence(self, context):
  95.         for gp in context.object.animation_data.action.groups:
  96.             for ch in gp.channels:
  97.                 for m in ch.modifiers:              
  98.                         m.influence = context.object.influence              
  99.  
  100. def update_phase_offset(self, context):
  101.         for gp in context.object.animation_data.action.groups:
  102.             for ch in gp.channels:
  103.                 for m in ch.modifiers:              
  104.                         m.phase_offset = context.object.phase_offset
  105.  
  106. def update_decal(self, context):
  107.         l = context.object.decal
  108.         for gp in context.object.animation_data.action.groups:
  109.             for ch in gp.channels:
  110.                 for m in ch.modifiers:
  111.                     m.blend_out = context.object.decal
  112.                     m.frame_end = m.frame_start + context.object.decal
  113.                        
  114. def register():
  115.     bpy.utils.register_module(__name__)
  116.     bpy.types.Object.influence = bpy.props.FloatProperty(default=1.0, min=0.0, max=1.0, update=update_influence)
  117.     bpy.types.Object.phase_offset = bpy.props.FloatProperty(default=0.0, min=-10.0, max=10.0, update=update_phase_offset)
  118.     bpy.types.Object.decal = bpy.props.IntProperty(default=5, min=0, max=50, update=update_decal)
  119.     bpy.types.Object.bool = bpy.props.BoolProperty(default=False)
  120.  
  121. def unregister():
  122.     bpy.utils.unregister_module(__name__)
  123.  
  124.  
  125. if __name__ == "__main__":
  126.     register()
  127.  
go to heaven