Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. # Basic principle, in Actions is:
  2. # Actions DO BELONG to Blender data, NOT to the object
  3.  
  4. # the actions are listed in the Actions proprety of Blender Data
  5. # The curves, that form the action are listed in f-curves property
  6. # The way to identify each croup of curves, are the
  7. # Groups, or, data_path properties.
  8. # Each curve has a keyframe item, listed in the Keyframes property.
  9.  
  10. import bpy
  11. import math
  12.  
  13. # get an object which will be associated to the animation
  14. obj = bpy.data.objects["Cube"]
  15.  
  16. # get the actions
  17. actions = bpy.data.actions
  18.  
  19. #create a name for the new action.
  20. newActionName = "Action#"+str(len(actions))
  21.  
  22. #instantiate new action
  23. newaction = bpy.data.actions.new(name=newActionName)
  24.  
  25. #creating curves for rotation
  26. fcu_Rx = newaction.fcurves.new("rotation_euler", 0, "Rotation")
  27. fcu_Ry = newaction.fcurves.new("rotation_euler", 1, "Rotation")
  28. fcu_Rz = newaction.fcurves.new("rotation_euler", 2, "Rotation")
  29.  
  30.  
  31. #inserting keyframes
  32. fcu_Rx.keyframe_points.insert(0, 0)
  33. fcu_Rx.keyframe_points.insert(10, math.radians(180))# angle in radians
  34.  
  35. fcu_Ry.keyframe_points.insert(0, 0)
  36. fcu_Ry.keyframe_points.insert(10,0)
  37.  
  38. fcu_Rz.keyframe_points.insert(0, 0)
  39. fcu_Rz.keyframe_points.insert(10,0)
  40.  
  41. # Change curve style.
  42. fcu_Ry.keyframe_points.insert(10, math.radians(90))
  43. # editando interpolação (o primeiro keyframe dita o modo de interpolação para o segmento)
  44. fcu_Ry.keyframe_points[0].interpolation = "BEZIER"
  45. #"LINEAR"
  46. #"CONSTANT"
  47. #"BEZIER"
  48.  
  49. #You can edit the curve handlers - left handle / right hadle
  50. fcu_Ry.keyframe_points[1].handle_left.x = 10
  51. fcu_Ry.keyframe_points[1].handle_left.y = 1
  52.  
  53. fcu_Ry.keyframe_points[1].handle_right.x = 12
  54. fcu_Ry.keyframe_points[1].handle_right.y = 1.8
  55.  
  56. #attach new action to the object
  57. obj.animation_data.action = newaction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement