Help wanted with bringing in animations from a game format

Hey guys, I’ve been working on a fairly hefty import script for Blender, supporting Dawn of War WHM model files.

It is nearly complete; the mesh objects, vertex weights for the mesh, parenting and bones all come in correctly.
I’m also reading in the animation data (which comes in the form of independent location and rotation keyframes, see the parsing code here: http://hastebin.com/remedokoca.py ), but no matter what I try, I’ve been stuck for weeks now trying to apply this in the correct space/coordinate system.

My only reference is an old Maxscript (shudder) which does the same thing.

Now, I parse the skeleton information like this: http://hastebin.com/pumuxuzeri.py
And later, using that information I correctly set up the rest pose like so: http://hastebin.com/xubamadetu.py
(If fix_rot is enabled and the relevant bits uncommented, the bones also face the same direction as the Maxscript spits out, which appears to be the “natural” and correct orientation)

The Maxscript reads and creates the skeleton like this: http://hastebin.com/imopuzinec.ms

So I’m reading in the skeleton, creating it correctly (and the rest pose is also correct) – you can pose models without issue. The issue I need help with arises with applying the animation data.
Same link as before, but here’s how it’s being parsed in my script; http://hastebin.com/remedokoca.py
(Here’s the current mess of commented out/unused attempts for applying an animation in my script; http://hastebin.com/utesucomin.py )
And here’s how it’s parsed and applied in the Maxscript; http://hastebin.com/dazucumisu.ms

As mentioned previously, I’ve tried many different combinations of space conversion, swapping axes and such, all with no joy. The collapsed ball of twitching model appears to be twitching with the right motions, just clearly in the wrong coordinate system.

I figured I’d ask here if anyone has any experience with 3ds Max and Blender’s bone/animation coordinate systems, or is that much of a wizard with matrices and quaternions that they can see what I’m doing wrong.

Any assistance is much appreciated!