From 749bc7577bd0b415ffcb31f56e39048c2dc7f9e0 Mon Sep 17 00:00:00 2001 From: TigerKat Date: Mon, 5 Apr 2021 12:56:32 +0930 Subject: [PATCH] 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. --- __init__.py | 2 +- import_anim.py | 25 +++++++++++++------------ import_skel.py | 3 +++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/__init__.py b/__init__.py index 186d509..28084f9 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ bl_info = { "name": "City of Heroes (.geo)", "author": "TigerKat", - "version": (0, 2, 6), + "version": (0, 2, 7), "blender": (2, 80, 0), "location": "File > Import/Export,", "description": "City of Heroes (.geo)", diff --git a/import_anim.py b/import_anim.py index 7f62373..bf3ed03 100644 --- a/import_anim.py +++ b/import_anim.py @@ -42,8 +42,8 @@ def getBoneRotation(bone, bone_trk_lookup, trk_rot_list, index): #return rot_s def convertAnimation(context, arm_obj, arm_data, anim, rescale = True): full_name = anim.header_name.decode("utf-8") - anim_name = full_name.split("/")[1].lstrip("skel_") - #todo: get all bones used in animation, and maximum length + anim_name = full_name.split("/")[1]#.lstrip("skel_") + #get all bones used in animation, and maximum fram count max_frames = 0 bone_ids = [] 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_scales.append(bone_scale) - #todo: create animation + #create animation if arm_obj.animation_data is None: arm_obj.animation_data_create() 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] pass else: nla_track = arm_obj.animation_data.nla_tracks.new() 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_rot_list = [] for i, bt in enumerate(anim.bone_tracks): @@ -101,12 +108,9 @@ def convertAnimation(context, arm_obj, arm_data, anim, rescale = True): pass trk_pos_list.append(pos_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): bone_name = bone_names[i] bone = arm_data.bones[bone_name] @@ -156,9 +160,6 @@ def convertAnimation(context, arm_obj, arm_data, anim, rescale = True): for crv in curves: crv.update() - #todo: create animation - - #todo: iterate over bones and generate frames data #todo: delete mid points for simple motions? pass diff --git a/import_skel.py b/import_skel.py index 7787f64..75e93bd 100644 --- a/import_skel.py +++ b/import_skel.py @@ -4,9 +4,11 @@ from mathutils import Vector, Quaternion try: from .anim import * from .bones import * + from .import_anim import convertAnimation except: from anim import * from bones import * + from import_anim import convertAnimation def import_fix_coord(v): return Vector((-v[0], -v[2], v[1])) @@ -89,6 +91,7 @@ def convertSkeleton(context, anim): bpy.ops.object.mode_set(mode='OBJECT') 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): #Load .anim file