@ -42,8 +42,8 @@ def getBoneRotation(bone, bone_trk_lookup, trk_rot_list, index):
#return rot_s
#return rot_s
def convertAnimation ( context , arm_obj , arm_data , anim , rescale = True ) :
def convertAnimation ( context , arm_obj , arm_data , anim , rescale = True ) :
full_name = anim . header_name . decode ( " utf-8 " )
full_name = anim . header_name . decode ( " utf-8 " )
anim_name = full_name . split ( " / " ) [ 1 ] . lstrip ( " skel_ " )
anim_name = full_name . split ( " / " ) [ 1 ] #.lstrip("skel_" )
# todo: get all bones used in animation, and maximum length
# get all bones used in animation, and maximum fram count
max_frames = 0
max_frames = 0
bone_ids = [ ]
bone_ids = [ ]
bone_names = [ ]
bone_names = [ ]
@ -70,16 +70,23 @@ def convertAnimation(context, arm_obj, arm_data, anim, rescale = True):
bone_scale = rescale and ( bone_arm_len / bone_trk_len ) or ( 1.0 )
bone_scale = rescale and ( bone_arm_len / bone_trk_len ) or ( 1.0 )
bone_scales . append ( bone_scale )
bone_scales . append ( bone_scale )
# todo: create animation
# create animation
if arm_obj . animation_data is None :
if arm_obj . animation_data is None :
arm_obj . animation_data_create ( )
arm_obj . animation_data_create ( )
if anim_name in arm_obj . animation_data . nla_tracks :
if anim_name in arm_obj . animation_data . nla_tracks :
#todo: resolve thi s
#todo: properly handle cases where the name already exist s
nla_track = arm_obj . animation_data . nla_tracks [ anim_name ]
nla_track = arm_obj . animation_data . nla_tracks [ anim_name ]
pass
pass
else :
else :
nla_track = arm_obj . animation_data . nla_tracks . new ( )
nla_track = arm_obj . animation_data . nla_tracks . new ( )
nla_track . name = anim_name
nla_track . name = anim_name
action = bpy . data . actions . new ( anim_name )
action . use_fake_user = True
nla_strip = nla_track . strips . new ( anim_name , 0 , action )
nla_strip . action_frame_start = 0
nla_strip . action_frame_end = max_frames
#Extract all position and rotation track data in blender coordinates.
trk_pos_list = [ ]
trk_pos_list = [ ]
trk_rot_list = [ ]
trk_rot_list = [ ]
for i , bt in enumerate ( anim . bone_tracks ) :
for i , bt in enumerate ( anim . bone_tracks ) :
@ -101,12 +108,9 @@ def convertAnimation(context, arm_obj, arm_data, anim, rescale = True):
pass
pass
trk_pos_list . append ( pos_list )
trk_pos_list . append ( pos_list )
trk_rot_list . append ( rot_list )
trk_rot_list . append ( rot_list )
action = bpy . data . actions . new ( anim_name )
action . use_fake_user = True
nla_strip = nla_track . strips . new ( anim_name , 0 , action )
nla_strip . action_frame_start = 0
nla_strip . action_frame_end = max_frames
#Iterate over bone tracks and generate FCurves for each of them.
for i , bt in enumerate ( anim . bone_tracks ) :
for i , bt in enumerate ( anim . bone_tracks ) :
bone_name = bone_names [ i ]
bone_name = bone_names [ i ]
bone = arm_data . bones [ bone_name ]
bone = arm_data . bones [ bone_name ]
@ -156,9 +160,6 @@ def convertAnimation(context, arm_obj, arm_data, anim, rescale = True):
for crv in curves :
for crv in curves :
crv . update ( )
crv . update ( )
#todo: create animation
#todo: iterate over bones and generate frames data
#todo: delete mid points for simple motions?
#todo: delete mid points for simple motions?
pass
pass