- 
	
	
	
		Baking actions 
		Script para bakear actions, escrito por vladius para Blender:
 (viene de este hilo).
 
	Código: 
 #.Bpy.
 
 Name: bake active action.
 
 Blender: 242a.
 
 Group: object.
 
 Toltip: bake constraints todo action keys.
 _author__ = vladius.
 _url__ = [vladius, fanatic, ru"]
 _versión__ = 1.0.
 _bpydoc__ = \
 Action bake let you bake the current object action constraints todo normal action keys.
 
 Usage:
 Select an object with an active action, and select bake active action from the object->scripts.
 
 Menú of the 3d view.
 
 From Blender import *
 From Blender import types.
 
 Import Sys.
 
 Def invertmatrix(mtx):
 Mtxi= Mathutils. Matrix(mtx)
 Mtxi, invert()
 Return mtxi.
 
 Pose_xform= [object. Pose. Loc,object. Pose. Rot].
 
 Def bakeaction(action, armatureobject):
 Bakes supplied action for supplied armature.
 
 Returns baked action.
 
 Pose=armatureobject, getpose ()
 Armature_data=armatureobject, getdata (),
 Pose_bones= pose, Bones, values()
 Rest_bones= armature_data, Bones.
 startframe= min(action, getframenumbers()),
 Endframe= max(action, getframenumbers()).
 
 Baked_action = armature. Nla. Newaction(baked_+action, getname ())
 old_quats={}
 Old_locs={}.
 
 Baked_locs={}
 Baked_quats={} action, setactive (armatureobject)
 For current_frame in xrange (startframe, endframe+1):
 Redraw().
 
 Set(curframe, current_frame) for i in range (len(pose_bones)):
 Bone_name=pose_bones[i].name.
 
 Rest_bone=rest_bones[bone_name]
 Matrix=Mathutils. Matrix(pose_bones[i].posematrix)
 #print pose Matrix\n, Matrix.
 
 Rest_matrix=Mathutils. Matrix(rest_bone, Matrix[armaturespace])
 #print rest Matrix\n, rest_matrix parent_bone=rest_bone, parent.
 
 Print frame:, current_frame.
 
 If parent_bone:
 Parent_pose_bone=pose, Bones[parent_bone, name]
 Matrix=Matrix*invertmatrix(parent_pose_bone, posematrix)
 Rest_matrix=rest_matrix*invertmatrix(parent_bone, Matrix[armaturespace]).
 #print before\n, Matrix.
 
 Print before quat\n, pose_bones[i].quat.
 #print localised postura Matrix\n, Matrix.
 #print localised rest Matrix\n, rest_matrix.
 
 Matrix=Matrix*invertmatrix(rest_matrix)
 old_quats[bone_name]=Mathutils. Quaternion(pose_bones[i].quat),
 Old_locs[bone_name]=Mathutils. Vector(pose_bones[i].loc).
 
 Baked_locs[bone_name]=Mathutils. Vector(Matrix.translationpart())
 Baked_quats[bone_name]=Mathutils. Quaternion(Matrix.toquat()).
 
 Baked_action, setactive (armatureobject)
 Set(curframe, current_frame)
 For I in range (len(pose_bones)):
 Pose_bones[i].quat=baked_quats[pose_bones[i].name]
 Pose_bones[i].loc=baked_locs[pose_bones[i].name]
 Pose_bones[i].insertkey(armatureobject, current_frame, pose_xform) action, setactive (armatureobject)
 Set(curframe, current_frame).
 
 For name, quat in old_quats, iteritems():
 Pose, Bones[name].quat=quat for name, Loc in old_locs, iteritems():
 Pose, Bones[name].loc=loc.
 pose, update ()
 Return baked_action.
 
 Def main():
 Main script driver.
 # get current scene.
 
 Scene= scene. Getcurrent()
 # get current object(must be armature)
 Armatureobject= scene, getactiveobject()
 If armatureobject, gettype ().=armature:
 Print select armature first.
 
 Return.
 # get current pose.
 
 For I in range (len(pose_bones)):
 Print rest_bones, values()[i].name.
 
 Print head(arm), rest_bones, values()[i].head[armaturespace]
 Print tail(arm), rest_bones, values()[i].tail[armaturespace]
 Print roll(arm), rest_bones, values()[i].roll[armaturespace]
 Print head(bone), rest_bones, values()[i].head[bonespace]
 Print tail(bone), rest_bones, values()[i].tail[bonespace]
 Print roll(bone), rest_bones, values()[i].roll[bonespace]
 Print armature-space\n, rest_bones, values()[i].Matrix[armaturespace]
 Print bone-space\n, rest_bones, values()[i].Matrix[bonespace].
 
 For I in range (len(pose_bones)):
 Print pose_bones[i].name.
 
 Print pose Matrix\n, pose_bones[i].posematrix.
 
 Print starting todo bake actions.
 
 Actions = armature. Nla. Getactions() for action_name, action in actions, iteritems():
 Bakeaction(action, pose_bones, rest_bones)
 Action=armatureobject, getaction().
 
 Bakeaction(action, armatureobject).
 
 If __name__==__main__:
 #import rpdb2, rpdb2.start_embedded_debugger(password,true)
 Main()