IPO Curve to OpenGL Matrix

Im trying to export a bone animation and integrate the animation in OpenGL, so Im trying to get the bone matrix of every frame (kinda baking) so I can export them and then apply the matrix to my object in OpenGL (glMultMatrixf) on a per frame basis. Now my question is:

  1. How can I get the OpenGL matrix of a bone for every frame based on its IPO curve? (LOC, ROT, SIZE) so I can do something like

glPushMatrix();
{
glMultMatrixf(object_matrix)

glPushMatrix();
{
glMulMatrixf(bone_matrix[ curr_frame ] ); // <- That’s the matrix im trying to get
render_object(my_object)
}
glPopMatrix();

}
glPopMatrix();

  1. How can I know which bone is assigned on every vertices?

Tks in advance!

ps: Is there someone who know how to get the Damp and RotDamp variables of a physic object? (located in Logic when Actor & Dynamic is selected)

Well in order to auto-answer my post the follow script do the job tks to cambo again :wink:



#====================================
# Bake IPO curve matrix
#====================================
def getBakedPoseData( ob_arm, start_frame, end_frame ):

	backup_action = ob_arm.action
	
	DUMMY_ACTION_NAME = 'DUMMY'

	try:
		
		new_action = bpy.data.actions[ DUMMY_ACTION_NAME ]
		
		if new_action.users:
			
			new_action = None
	
	except:
		
		new_action = None
	
	if not new_action:
		
		new_action = bpy.data.actions.new(DUMMY_ACTION_NAME)
		new_action.fakeUser = False


	bake_data = [ {} for i in xrange( 1 + end_frame - start_frame ) ]
	
	pose				  = ob_arm.getPose()
	armature_data =	ob_arm.getData();
	pose_bones		=	pose.bones
	

	armature_bone_data = []
	bones_index = {}

	for bone_name, rest_bone in armature_data.bones.items():
		
		pose_bone = pose_bones[ bone_name ]
		
		rest_matrix 		= rest_bone.matrix['ARMATURESPACE']
		rest_matrix_inv = rest_matrix.copy().invert()
		
		armature_bone_data.append( [len(bones_index), -1, bone_name, rest_bone, rest_matrix, rest_matrix_inv, pose_bone, None ])
		
		bones_index[ bone_name ] = len( bones_index )
	
	
	for bone_name, pose_bone in pose_bones.items():
		
		parent = pose_bone.parent
		
		
		if parent:
		
			bone_index= bones_index[bone_name]
			parent_index= bones_index[parent.name]
			armature_bone_data[ bone_index ][1]= parent_index
	

	frame_index = 0
	
	for current_frame in xrange( start_frame, end_frame + 1 ):

		ob_arm.action = backup_action
		
		Blender.Set( 'curframe', current_frame )
		ob_arm.action = new_action
		
		
		for index, parent_index, bone_name, rest_bone, rest_matrix, rest_matrix_inv, pose_bone, ipo in armature_bone_data:

			matrix = pose_bone.poseMatrix
			
			parent_bone= rest_bone.parent
			
			if parent_index != -1:
				
				parent_pose_matrix 		 = armature_bone_data[parent_index][6].poseMatrix
				parent_bone_matrix_inv = armature_bone_data[parent_index][5]
				
				matrix 			= matrix * parent_pose_matrix.copy().invert()
				rest_matrix = rest_matrix * parent_bone_matrix_inv
			
			matrix = matrix * rest_matrix.copy().invert()
	
			bake_data[ frame_index ][ bone_name ] = matrix
		
		frame_index += 1
	
	ob_arm.action = backup_action
	Blender.Set( 'curframe', 1 )
	
	return bake_data