I'm working on a tool to import a biped from a DirectX engine that uses Left-handed coordinate system to 3ds Max that uses a right-handed one.
I managed to achieve the initial positions of the biped by multiplying all the transformations matrices by this initial matrix (the initial positions are written in a 4x4 matrix):
[1, 0, 0 ] [0, -1.62921e-07, 1 ] [0, 1, 1.62921e-07] [0, 0, 0 ]
3ds uses the classic 4x4 matrix with the difference that it removes the last column, so this is pretty much the DirectX 4x4 matrix with the rotations and scale on the first 3 lows and the translation is in the last one.
I achieved this matrix by doing the following on maxscript:
rotation = (0, 0.707107, -0.707107, 0) //rotate 90 on x and 180 on z scale = (1, 1, -1)
Everything is fine here until i try to apply quaternions on each keyframe, which half of the time imports the rotation fine, but backwards. I'm not sure how to express this properly so i will show an image of what happens:
In this example, the first frames are fine on the legs ( the arm is messed up in the same way but it's not as obvious)
And then the rotation of the leg is totally backwards in the next frames.
What i do to implement the animation is to apply to the TCB Rotation controller the quaternion locally. Sometimes the result is right, and sometimes the result isn't, and i'm not certainly sure why or how to fix it. I tried inversing them, and some operations that the max api gives me, but not of them seem to work. Conjugating the quaternion seems to give me some kind of better result (which is the current one), but still gives me flaws. The line of code is:
in coordsys local anode.rotation.controller[node_layer_index].controller.value = conjugate arot
This applies the rotation using the conjugated version of the quaternion.
I attempted to do the exact same thing in Maya, which gave me a better result than the current one, but the problem is, that since i'm using euler and i don't seem to actually know how to process it properly, the interpolation is totally off, but the animation seems to be processde fine. I issued this problem in another question that ended up unanswered, if you think you can help me out in fixing it in maya, the question is here: https://stackoverflow.com/questions/40581600/interpolation-between-two-keys-makes-are-off-after-python-importantion
I tried also to import the animation straight from the original axis, even if everything is flipped, but the problem remains, so it seems to be an issue of the way Max does the thing.
I would greatly appreciate any kinds of suggestions, or any way to fix this manually in the editor, even if it is in the curve editor, it does not have to be directly fixed on the script.