Skeleton import now imports the skeleton's animation. Cleaned up some comments. Fixed a bug causing any characters in 'skel_' being dropped from the start of an animation's import name.

master
TigerKat 4 years ago
parent 43bf1a79f8
commit 749bc7577b

@ -2,7 +2,7 @@
bl_info = { bl_info = {
"name": "City of Heroes (.geo)", "name": "City of Heroes (.geo)",
"author": "TigerKat", "author": "TigerKat",
"version": (0, 2, 6), "version": (0, 2, 7),
"blender": (2, 80, 0), "blender": (2, 80, 0),
"location": "File > Import/Export,", "location": "File > Import/Export,",
"description": "City of Heroes (.geo)", "description": "City of Heroes (.geo)",

@ -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 this #todo: properly handle cases where the name already exists
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

@ -4,9 +4,11 @@ from mathutils import Vector, Quaternion
try: try:
from .anim import * from .anim import *
from .bones import * from .bones import *
from .import_anim import convertAnimation
except: except:
from anim import * from anim import *
from bones import * from bones import *
from import_anim import convertAnimation
def import_fix_coord(v): def import_fix_coord(v):
return Vector((-v[0], -v[2], v[1])) return Vector((-v[0], -v[2], v[1]))
@ -89,6 +91,7 @@ def convertSkeleton(context, anim):
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
arm_obj.hide_viewport = is_hidden arm_obj.hide_viewport = is_hidden
convertAnimation(context, arm_obj, arm_data, anim, rescale = False)
def load(operator, context, scale = 1.0, filepath = "", global_matrix = None, use_mesh_modifiers = True, ignore_lod = True): def load(operator, context, scale = 1.0, filepath = "", global_matrix = None, use_mesh_modifiers = True, ignore_lod = True):
#Load .anim file #Load .anim file

Loading…
Cancel
Save