Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Basic principle, in Actions is:
- # Actions DO BELONG to Blender data, NOT to the object
- # the actions are listed in the Actions proprety of Blender Data
- # The curves, that form the action are listed in f-curves property
- # The way to identify each croup of curves, are the
- # Groups, or, data_path properties.
- # Each curve has a keyframe item, listed in the Keyframes property.
- import bpy
- import math
- # get an object which will be associated to the animation
- obj = bpy.data.objects["Cube"]
- # get the actions
- actions = bpy.data.actions
- #create a name for the new action.
- newActionName = "Action#"+str(len(actions))
- #instantiate new action
- newaction = bpy.data.actions.new(name=newActionName)
- #creating curves for rotation
- fcu_Rx = newaction.fcurves.new("rotation_euler", 0, "Rotation")
- fcu_Ry = newaction.fcurves.new("rotation_euler", 1, "Rotation")
- fcu_Rz = newaction.fcurves.new("rotation_euler", 2, "Rotation")
- #inserting keyframes
- fcu_Rx.keyframe_points.insert(0, 0)
- fcu_Rx.keyframe_points.insert(10, math.radians(180))# angle in radians
- fcu_Ry.keyframe_points.insert(0, 0)
- fcu_Ry.keyframe_points.insert(10,0)
- fcu_Rz.keyframe_points.insert(0, 0)
- fcu_Rz.keyframe_points.insert(10,0)
- # Change curve style.
- fcu_Ry.keyframe_points.insert(10, math.radians(90))
- # editando interpolação (o primeiro keyframe dita o modo de interpolação para o segmento)
- fcu_Ry.keyframe_points[0].interpolation = "BEZIER"
- #"LINEAR"
- #"CONSTANT"
- #"BEZIER"
- #You can edit the curve handlers - left handle / right hadle
- fcu_Ry.keyframe_points[1].handle_left.x = 10
- fcu_Ry.keyframe_points[1].handle_left.y = 1
- fcu_Ry.keyframe_points[1].handle_right.x = 12
- fcu_Ry.keyframe_points[1].handle_right.y = 1.8
- #attach new action to the object
- obj.animation_data.action = newaction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement