Models become oddly distorted when copying animation data?

So, I’ve generated a large number of simple humanoid models procedurally using Blender (and MakeHuman/MakeClothes/MakeTarget). They look like the left and middle characters in this image:

https://imgur.com/esZ2mIw


I then went ahead and created some simple actions with a few keyframes each for one of these models (for the little guy on the left, to be specific). For example, in the above image the little guy and the guy on the right are both using a simple “slash” action, and the still image captures them in a pose with their arms raised back preparing to swing.

Because there are a large number of these very similar characters, and because they all have the same armature (same number, names of bones with identical connections between bones), I thought it would be neat to copy the animation data from the one little guy on the left to all of the other procedurally generated characters.

I did that in two different ways. In one of those, I copy all of the animation data’s properties like:


reference_obj = bpy.data.objects['Game_engine']
ad = reference_obj.animation_data
properties = [p.identifier for p in ad.bl_rna.properties if not p.is_readonly]

target_obj = bpy.data.objects['Game_engine.001']
target_ad = target_obj.animation_data

for prop in properties:
    setattr(target_ad, prop, getattr(ad, prop)

Unfortunately, this distorted most of the models to which the data was copied; for example, in copying the animation data from the little guy on the left to the (no-keyframes-or-actions) guy in the middle to get the (now-has-keyframes-and-actions) guy on the right, the middle guy obviously gets move off center and rotated a bit.

Since the above approach is a bit of a sledgehammer - it sets all animation data the same even though all of my very simple animations just involve changing bone quaternions a bit - I then tried a second approach where I did things like:


    while {'FINISHED'} == bpy.ops.screen.keyframe_jump():
        frame_number = bpy.context.scene.frame_current
        ref_axn_frames[axn].append(frame_number)
        for bone in reference_obj.pose.bones[:]:
            ref_bone_rotations[(axn,bone.name,frame_number)] = bone.rotation_quaternion

and then iterated over the bones in the target object, setting their quaternions and adding actions / inserting keyframes to mimic the little guy’s animations. Unfortunately, the problem apparently wasn’t with the ‘sledgehammer’, as this second approach also distorted the second guy.

This is a little mystifying to me, because if I just enter pose mode myself and rotate each of the bones to match the kid’s bones, the animations turn out identical. So, I figure I must be unintentionally modifying some additional properties here without knowing it (or, perhaps, the opposite - not altering properties I should be).

Any thoughts on why this might be occurring? (Also, I’m happy to post the rest of the two copyAnimations.py scripts if that would help, was just trying to highlight the relevant details above.)